Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of FRDM-TFC by
Revision 3:23cce037011f, committed 2013-08-15
- Comitter:
- emh203
- Date:
- Thu Aug 15 23:26:19 2013 +0000
- Parent:
- 2:ce4a273be708
- Child:
- 4:8a4a3fc59e57
- Commit message:
- 1.) Fixed issue with Servo duty cycle calculation
; 2.) Verified Case 0,1 2 of the test program (servo steering and drive). The Camera code is OK but there seems to be an issue on my machine with the KL25Z virtual MBED serial port.
Changed in this revision
--- a/TFC.cpp Wed Jul 17 19:31:32 2013 +0000
+++ b/TFC.cpp Thu Aug 15 23:26:19 2013 +0000
@@ -332,7 +332,6 @@
volatile uint16_t QueuedServo0Val;
volatile uint16_t QueuedServo1Val;
-volatile uint8_t TFC_LineScanDataReady;
volatile uint16_t *LineScanImage0WorkingBuffer;
volatile uint16_t *LineScanImage1WorkingBuffer;
@@ -340,13 +339,17 @@
volatile uint16_t LineScanImage1Buffer[2][128];
volatile uint8_t LineScanWorkingBuffer;
+volatile uint16_t * TFC_LineScanImage0;
+volatile uint16_t * TFC_LineScanImage1;
+volatile uint8_t TFC_LineScanImageReady;
+
volatile uint16_t PotADC_Value[2];
volatile uint16_t BatSenseADC_Value;
volatile uint16_t CurrentADC_State;
volatile uint8_t CurrentLineScanPixel;
volatile uint8_t CurrentLineScanChannel;
volatile uint32_t TFC_ServoTicker;
-volatile uint16_t * TFC_LineScanCameraData[2];
+
void TFC_SetServoDutyCycle(uint8_t ServoNumber, float DutyCycle);
void TFC_InitLineScanCamera();
@@ -564,7 +567,7 @@
void TFC_SetServo(uint8_t ServoNumber, float Position)
{
TFC_SetServoDutyCycle(ServoNumber ,
- ((Position + 1.0)/2) * ((_ServoDutyCycleMax - _ServoDutyCycleMin)+_ServoDutyCycleMin) );
+ ((Position + 1.0)/2) * ((_ServoDutyCycleMax - _ServoDutyCycleMin))+_ServoDutyCycleMin) ;
}
@@ -852,18 +855,18 @@
LineScanImage0WorkingBuffer = &LineScanImage0Buffer[1][0];
LineScanImage1WorkingBuffer = &LineScanImage1Buffer[1][0];
- TFC_LineScanCameraData[0] = &LineScanImage0Buffer[0][0];
- TFC_LineScanCameraData[1] = &LineScanImage1Buffer[0][0];
+ TFC_LineScanImage0 = &LineScanImage0Buffer[0][0];
+ TFC_LineScanImage1 = &LineScanImage1Buffer[0][0];
} else {
LineScanWorkingBuffer = 0;
LineScanImage0WorkingBuffer = &LineScanImage0Buffer[0][0];
LineScanImage1WorkingBuffer = &LineScanImage1Buffer[0][0];
- TFC_LineScanCameraData[0] = &LineScanImage0Buffer[1][0];
- TFC_LineScanCameraData[1] = &LineScanImage1Buffer[1][0];
+ TFC_LineScanImage0 = &LineScanImage0Buffer[1][0];
+ TFC_LineScanImage1 = &LineScanImage1Buffer[1][0];
}
- TFC_LineScanDataReady++;
+ TFC_LineScanImageReady++;
}
break;
@@ -892,8 +895,8 @@
LineScanImage0WorkingBuffer = &LineScanImage0Buffer[LineScanWorkingBuffer][0];
LineScanImage1WorkingBuffer = &LineScanImage1Buffer[LineScanWorkingBuffer][0];
- TFC_LineScanCameraData[0] = &LineScanImage0Buffer[1][0];
- TFC_LineScanCameraData[1] = &LineScanImage1Buffer[1][0];
+ TFC_LineScanImage0 = &LineScanImage0Buffer[1][0];
+ TFC_LineScanImage1 = &LineScanImage1Buffer[1][0];
}
@@ -908,12 +911,11 @@
{
//Clock Setup for the TPM requires a couple steps.
-
//1st, set the clock mux
//See Page 124 of f the KL25 Sub-Family Reference Manual, Rev. 3, September 2012
- // SIM->SOPT2 |= SIM_SOPT2_PLLFLLSEL_MASK;// We Want MCGPLLCLK/2 (See Page 196 of the KL25 Sub-Family Reference Manual, Rev. 3, September 2012)
- // SIM->SOPT2 &= ~(SIM_SOPT2_TPMSRC_MASK);
- // SIM->SOPT2 |= SIM_SOPT2_TPMSRC(1); //We want the MCGPLLCLK/2 (See Page 196 of the KL25 Sub-Family Reference Manual, Rev. 3, September 2012)
+ SIM->SOPT2 |= SIM_SOPT2_PLLFLLSEL_MASK;// We Want MCGPLLCLK/2 (See Page 196 of the KL25 Sub-Family Reference Manual, Rev. 3, September 2012)
+ SIM->SOPT2 &= ~(SIM_SOPT2_TPMSRC_MASK);
+ SIM->SOPT2 |= SIM_SOPT2_TPMSRC(1); //We want the MCGPLLCLK/2 (See Page 196 of the KL25 Sub-Family Reference Manual, Rev. 3, September 2012)
//Enable the Clock to the FTM0 Module
@@ -988,3 +990,47 @@
{
return (((float)BatSenseADC_Value/(float)(ADC_MAX_CODE)) * 3.0);// * ((47000.0+10000.0)/10000.0);
}
+
+
+void TFC_SetBatteryLED_Level(uint8_t BattLevel)
+{
+ switch(BattLevel)
+ {
+ default:
+ case 0:
+ TFC_BAT_LED0_OFF;
+ TFC_BAT_LED1_OFF;
+ TFC_BAT_LED2_OFF;
+ TFC_BAT_LED3_OFF;
+ break;
+
+ case 1:
+ TFC_BAT_LED0_ON;
+ TFC_BAT_LED1_OFF;
+ TFC_BAT_LED2_OFF;
+ TFC_BAT_LED3_OFF;
+ break;
+
+ case 2:
+ TFC_BAT_LED0_ON;
+ TFC_BAT_LED1_ON;
+ TFC_BAT_LED2_OFF;
+ TFC_BAT_LED3_OFF;
+ break;
+
+ case 3:
+ TFC_BAT_LED0_ON;
+ TFC_BAT_LED1_ON;
+ TFC_BAT_LED2_ON;
+ TFC_BAT_LED3_OFF;
+ break;
+
+ case 4:
+ TFC_BAT_LED0_ON;
+ TFC_BAT_LED1_ON;
+ TFC_BAT_LED2_ON;
+ TFC_BAT_LED3_ON;
+ break;
+
+ }
+}
--- a/TFC.h Wed Jul 17 19:31:32 2013 +0000 +++ b/TFC.h Thu Aug 15 23:26:19 2013 +0000 @@ -218,18 +218,32 @@ float TFC_ReadBatteryVoltage(); + +/** Sets the Battery level indiciate +* +* @param BattLevel A number betwween 0 and 4. This will light the bar from left to right with the specifified number of segments. +* +*/ +void TFC_SetBatteryLED_Level(uint8_t BattLevel); + + /** Pointer to two channels of line scan camera data. Each channel is 128 points of uint8_t's. Note that the underlying implementation is ping-pong buffer These pointers will point to the *inactive buffer. * */ -extern volatile uint16_t * TFC_LineScanCameraData[2]; +extern volatile uint16_t * TFC_LineScanImage0; +extern volatile uint16_t * TFC_LineScanImage1; + /** This flag will increment when a new frame is ready. Check for a non zero value (and reset to zero!) when you want to read the camera(s) * */ -extern volatile uint8_t TFC_LineScanCameraDataReady; +extern volatile uint8_t TFC_LineScanImageReady; + + + /** @} */
--- a/main.cpp Wed Jul 17 19:31:32 2013 +0000
+++ b/main.cpp Thu Aug 15 23:26:19 2013 +0000
@@ -1,79 +1,183 @@
-#include "mbed.h"
-#include "TFC.h"
-
-DigitalOut myled(LED1);
-Ticker TFC_TickerObj;
-Serial PC(USBTX,USBRX);
-
-#define NUM_TFC_TICKERS 4
-
-volatile uint32_t TFC_Ticker[NUM_TFC_TICKERS];
-
-void TFC_TickerUpdate()
-{
- int i;
-
- for(i=0; i<NUM_TFC_TICKERS; i++) {
- if(TFC_Ticker[i]<0xFFFFFFFF) {
- TFC_Ticker[0]++;
- }
- }
-}
-
-
-
-
-int main()
-{
- // int i;
-
-
- PC.baud(9600);
- TFC_TickerObj.attach_us(&TFC_TickerUpdate,1000);
- __disable_irq();
-
- TFC_Init();
- __enable_irq();
-// TFC_Init();
- while(1)
- {
-
- if(TFC_ServoTicker >0)
- {
- TFC_ServoTicker = 0;
-
- TFC_SetBatteryLED(TFC_GetDIP_Switch());
-
- if(TFC_DIP_SWITCH_0_ON) {
- if(TFC_PUSH_BUTTON_0_PRESSED)
- TFC_SetServo(0,0.2);
- else if(TFC_PUSH_BUTTON_1_PRESSED)
- TFC_SetServo(0,-0.2);
- else
- TFC_SetServo(0,TFC_ReadPot(0));
- }
-
-
- if(TFC_DIP_SWITCH_1_ON) {
- TFC_HBRIDGE_ENABLE;
- TFC_SetMotorPWM(TFC_ReadPot(1) ,TFC_ReadPot(1));
- } else {
- TFC_HBRIDGE_DISABLE;
- }
-
-
- }
-
-
- if(TFC_Ticker[0]>500)
- {
- TFC_Ticker[0] = 0;
- PC.printf("Servo Ticker %i",TFC_ServoTicker);
- }
-
-
-
- }
-
-}
-
\ No newline at end of file
+#include "mbed.h"
+#include "TFC.h"
+
+
+//This macro is to maintain compatibility with Codewarrior version of the sample. This version uses the MBED libraries for serial port access
+Serial PC(USBTX,USBRX);
+
+#define TERMINAL_PRINTF PC.printf
+
+
+ //This ticker code is used to maintain compability with the Codewarrior version of the sample. This code uses an MBED Ticker for background timing.
+
+#define NUM_TFC_TICKERS 4
+
+Ticker TFC_TickerObj;
+
+volatile uint32_t TFC_Ticker[NUM_TFC_TICKERS];
+
+void TFC_TickerUpdate()
+{
+ int i;
+
+ for(i=0; i<NUM_TFC_TICKERS; i++)
+ {
+ if(TFC_Ticker[i]<0xFFFFFFFF)
+ {
+ TFC_Ticker[i]++;
+ }
+ }
+}
+
+
+
+
+int main()
+{
+ uint32_t i,j,t = 0;
+
+ PC.baud(115200);
+ TFC_TickerObj.attach_us(&TFC_TickerUpdate,2000);
+
+ TFC_Init();
+
+ for(;;)
+ {
+ //TFC_Task must be called in your main loop. This keeps certain processing happy (I.E. Serial port queue check)
+ // TFC_Task();
+
+ //This Demo program will look at the middle 2 switch to select one of 4 demo modes.
+ //Let's look at the middle 2 switches
+ switch((TFC_GetDIP_Switch()>>1)&0x03)
+ {
+ default:
+ case 0 :
+ //Demo mode 0 just tests the switches and LED's
+ if(TFC_PUSH_BUTTON_0_PRESSED)
+ TFC_BAT_LED0_ON;
+ else
+ TFC_BAT_LED0_OFF;
+
+ if(TFC_PUSH_BUTTON_1_PRESSED)
+ TFC_BAT_LED3_ON;
+ else
+ TFC_BAT_LED3_OFF;
+
+
+ if(TFC_GetDIP_Switch()&0x01)
+ TFC_BAT_LED1_ON;
+ else
+ TFC_BAT_LED1_OFF;
+
+ if(TFC_GetDIP_Switch()&0x08)
+ TFC_BAT_LED2_ON;
+ else
+ TFC_BAT_LED2_OFF;
+
+ break;
+
+ case 1:
+
+ //Demo mode 1 will just move the servos with the on-board potentiometers
+ if(TFC_Ticker[0]>=20)
+ {
+ TFC_Ticker[0] = 0; //reset the Ticker
+ //Every 20 mSeconds, update the Servos
+ TFC_SetServo(0,TFC_ReadPot(0));
+ TFC_SetServo(1,TFC_ReadPot(1));
+ }
+ //Let's put a pattern on the LEDs
+ if(TFC_Ticker[1] >= 125)
+ {
+ TFC_Ticker[1] = 0;
+ t++;
+ if(t>4)
+ {
+ t=0;
+ }
+ TFC_SetBatteryLED_Level(t);
+ }
+
+ TFC_SetMotorPWM(0,0); //Make sure motors are off
+ TFC_HBRIDGE_DISABLE;
+
+
+ break;
+
+ case 2 :
+
+ //Demo Mode 2 will use the Pots to make the motors move
+ TFC_HBRIDGE_ENABLE;
+
+ TFC_SetMotorPWM(TFC_ReadPot(0),TFC_ReadPot(1));
+
+
+ //Let's put a pattern on the LEDs
+ if(TFC_Ticker[1] >= 125)
+ {
+ TFC_Ticker[1] = 0;
+ t++;
+ if(t>4)
+ {
+ t=0;
+ }
+ TFC_SetBatteryLED_Level(t);
+ }
+ break;
+
+ case 3 :
+
+ //Demo Mode 3 will be in Freescale Garage Mode. It will beam data from the Camera to the
+ //Labview Application
+
+ //note that there are some issues
+ if(TFC_Ticker[0]>1000 && TFC_LineScanImageReady>0)
+ {
+ TFC_Ticker[0] = 0;
+ TFC_LineScanImageReady=0;
+ TERMINAL_PRINTF("\r\n");
+ TERMINAL_PRINTF("L:");
+
+ if(t==0)
+ t=4;
+ else
+ t--;
+
+ TFC_SetBatteryLED_Level(t);
+
+ for(i=0;i<8;i++)
+ {
+ for(j=0;j<16;j++)
+ {
+ TERMINAL_PRINTF("%X,",TFC_LineScanImage0[(i*8)+j]);
+
+ }
+ wait_ms(10);
+ }
+
+ for(i=0;i<8;i++)
+ {
+ for(j=0;j<16;j++)
+ {
+ TERMINAL_PRINTF("%X",TFC_LineScanImage1[(i*8)+j]);
+
+ if((i*8)+j==127)
+ TERMINAL_PRINTF("\r\n",TFC_LineScanImage1[(i*8)+j]);
+ else
+ TERMINAL_PRINTF(",",TFC_LineScanImage1[(i*8)+j]);
+ }
+
+ wait_ms(10);
+ }
+
+ }
+
+
+
+ break;
+ }
+ }
+
+
+}
+
--- a/mbed.bld Wed Jul 17 19:31:32 2013 +0000 +++ b/mbed.bld Thu Aug 15 23:26:19 2013 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/mbed_official/code/mbed/builds/b3110cd2dd17 \ No newline at end of file +http://mbed.org/users/mbed_official/code/mbed/builds/5798e58a58b1 \ No newline at end of file
