An example program that uses FRDM-TFC library written by Eli Hughes.

Dependencies:   FRDM-TFC

Fork of TFC-TEST by Daniel Hadad

Committer:
redxeth
Date:
Tue Apr 15 02:38:04 2014 +0000
Revision:
0:6432166d0781
Child:
1:1dd8d5ffdd02
First version of demo program for FRDM-TFC library.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
redxeth 0:6432166d0781 1 #include "mbed.h"
redxeth 0:6432166d0781 2 #include "TFC.h"
redxeth 0:6432166d0781 3
redxeth 0:6432166d0781 4
redxeth 0:6432166d0781 5 //This macro is to maintain compatibility with Codewarrior version of the sample. This version uses the MBED libraries for serial port access
redxeth 0:6432166d0781 6 Serial PC(USBTX,USBRX);
redxeth 0:6432166d0781 7
redxeth 0:6432166d0781 8 #define TERMINAL_PRINTF PC.printf
redxeth 0:6432166d0781 9
redxeth 0:6432166d0781 10
redxeth 0:6432166d0781 11 //This ticker code is used to maintain compability with the Codewarrior version of the sample. This code uses an MBED Ticker for background timing.
redxeth 0:6432166d0781 12
redxeth 0:6432166d0781 13 #define NUM_TFC_TICKERS 4
redxeth 0:6432166d0781 14
redxeth 0:6432166d0781 15 Ticker TFC_TickerObj;
redxeth 0:6432166d0781 16
redxeth 0:6432166d0781 17 volatile uint32_t TFC_Ticker[NUM_TFC_TICKERS];
redxeth 0:6432166d0781 18
redxeth 0:6432166d0781 19 void TFC_TickerUpdate()
redxeth 0:6432166d0781 20 {
redxeth 0:6432166d0781 21 int i;
redxeth 0:6432166d0781 22
redxeth 0:6432166d0781 23 for(i=0; i<NUM_TFC_TICKERS; i++)
redxeth 0:6432166d0781 24 {
redxeth 0:6432166d0781 25 if(TFC_Ticker[i]<0xFFFFFFFF)
redxeth 0:6432166d0781 26 {
redxeth 0:6432166d0781 27 TFC_Ticker[i]++;
redxeth 0:6432166d0781 28 }
redxeth 0:6432166d0781 29 }
redxeth 0:6432166d0781 30 }
redxeth 0:6432166d0781 31
redxeth 0:6432166d0781 32
redxeth 0:6432166d0781 33
redxeth 0:6432166d0781 34
redxeth 0:6432166d0781 35 int main()
redxeth 0:6432166d0781 36 {
redxeth 0:6432166d0781 37 uint32_t i,t = 0;
redxeth 0:6432166d0781 38
redxeth 0:6432166d0781 39 PC.baud(115200);
redxeth 0:6432166d0781 40 TFC_TickerObj.attach_us(&TFC_TickerUpdate,2000);
redxeth 0:6432166d0781 41
redxeth 0:6432166d0781 42 TFC_Init();
redxeth 0:6432166d0781 43
redxeth 0:6432166d0781 44 for(;;)
redxeth 0:6432166d0781 45 {
redxeth 0:6432166d0781 46 //TFC_Task must be called in your main loop. This keeps certain processing happy (I.E. Serial port queue check)
redxeth 0:6432166d0781 47 // TFC_Task();
redxeth 0:6432166d0781 48
redxeth 0:6432166d0781 49 //This Demo program will look at the middle 2 switch to select one of 4 demo modes.
redxeth 0:6432166d0781 50 //Let's look at the middle 2 switches
redxeth 0:6432166d0781 51 switch((TFC_GetDIP_Switch()>>1)&0x03)
redxeth 0:6432166d0781 52 {
redxeth 0:6432166d0781 53 default:
redxeth 0:6432166d0781 54 case 0 :
redxeth 0:6432166d0781 55 //Demo mode 0 just tests the switches and LED's
redxeth 0:6432166d0781 56 if(TFC_PUSH_BUTTON_0_PRESSED)
redxeth 0:6432166d0781 57 TFC_BAT_LED0_ON;
redxeth 0:6432166d0781 58 else
redxeth 0:6432166d0781 59 TFC_BAT_LED0_OFF;
redxeth 0:6432166d0781 60
redxeth 0:6432166d0781 61 if(TFC_PUSH_BUTTON_1_PRESSED)
redxeth 0:6432166d0781 62 TFC_BAT_LED3_ON;
redxeth 0:6432166d0781 63 else
redxeth 0:6432166d0781 64 TFC_BAT_LED3_OFF;
redxeth 0:6432166d0781 65
redxeth 0:6432166d0781 66
redxeth 0:6432166d0781 67 if(TFC_GetDIP_Switch()&0x01)
redxeth 0:6432166d0781 68 TFC_BAT_LED1_ON;
redxeth 0:6432166d0781 69 else
redxeth 0:6432166d0781 70 TFC_BAT_LED1_OFF;
redxeth 0:6432166d0781 71
redxeth 0:6432166d0781 72 if(TFC_GetDIP_Switch()&0x08)
redxeth 0:6432166d0781 73 TFC_BAT_LED2_ON;
redxeth 0:6432166d0781 74 else
redxeth 0:6432166d0781 75 TFC_BAT_LED2_OFF;
redxeth 0:6432166d0781 76
redxeth 0:6432166d0781 77 break;
redxeth 0:6432166d0781 78
redxeth 0:6432166d0781 79 case 1:
redxeth 0:6432166d0781 80
redxeth 0:6432166d0781 81 //Demo mode 1 will just move the servos with the on-board potentiometers
redxeth 0:6432166d0781 82 if(TFC_Ticker[0]>=20)
redxeth 0:6432166d0781 83 {
redxeth 0:6432166d0781 84 TFC_Ticker[0] = 0; //reset the Ticker
redxeth 0:6432166d0781 85 //Every 20 mSeconds, update the Servos
redxeth 0:6432166d0781 86 TFC_SetServo(0,TFC_ReadPot(0));
redxeth 0:6432166d0781 87 TFC_SetServo(1,TFC_ReadPot(1));
redxeth 0:6432166d0781 88 }
redxeth 0:6432166d0781 89 //Let's put a pattern on the LEDs
redxeth 0:6432166d0781 90 if(TFC_Ticker[1] >= 125)
redxeth 0:6432166d0781 91 {
redxeth 0:6432166d0781 92 TFC_Ticker[1] = 0;
redxeth 0:6432166d0781 93 t++;
redxeth 0:6432166d0781 94 if(t>4)
redxeth 0:6432166d0781 95 {
redxeth 0:6432166d0781 96 t=0;
redxeth 0:6432166d0781 97 }
redxeth 0:6432166d0781 98 TFC_SetBatteryLED_Level(t);
redxeth 0:6432166d0781 99 }
redxeth 0:6432166d0781 100
redxeth 0:6432166d0781 101 TFC_SetMotorPWM(0,0); //Make sure motors are off
redxeth 0:6432166d0781 102 TFC_HBRIDGE_DISABLE;
redxeth 0:6432166d0781 103
redxeth 0:6432166d0781 104
redxeth 0:6432166d0781 105 break;
redxeth 0:6432166d0781 106
redxeth 0:6432166d0781 107 case 2 :
redxeth 0:6432166d0781 108
redxeth 0:6432166d0781 109 //Demo Mode 2 will use the Pots to make the motors move
redxeth 0:6432166d0781 110 TFC_HBRIDGE_ENABLE;
redxeth 0:6432166d0781 111
redxeth 0:6432166d0781 112 TFC_SetMotorPWM(TFC_ReadPot(0),TFC_ReadPot(1));
redxeth 0:6432166d0781 113
redxeth 0:6432166d0781 114
redxeth 0:6432166d0781 115 //Let's put a pattern on the LEDs
redxeth 0:6432166d0781 116 if(TFC_Ticker[1] >= 125)
redxeth 0:6432166d0781 117 {
redxeth 0:6432166d0781 118 TFC_Ticker[1] = 0;
redxeth 0:6432166d0781 119 t++;
redxeth 0:6432166d0781 120 if(t>4)
redxeth 0:6432166d0781 121 {
redxeth 0:6432166d0781 122 t=0;
redxeth 0:6432166d0781 123 }
redxeth 0:6432166d0781 124 TFC_SetBatteryLED_Level(t);
redxeth 0:6432166d0781 125 }
redxeth 0:6432166d0781 126 break;
redxeth 0:6432166d0781 127
redxeth 0:6432166d0781 128 case 3 :
redxeth 0:6432166d0781 129
redxeth 0:6432166d0781 130
redxeth 0:6432166d0781 131 //Demo Mode 3 will be in Freescale Garage Mode. It will beam data from the Camera to the
redxeth 0:6432166d0781 132 //Labview Application
redxeth 0:6432166d0781 133
redxeth 0:6432166d0781 134
redxeth 0:6432166d0781 135 if(TFC_Ticker[0]>50 && TFC_LineScanImageReady>0)
redxeth 0:6432166d0781 136 {
redxeth 0:6432166d0781 137 TFC_Ticker[0] = 0;
redxeth 0:6432166d0781 138 TFC_LineScanImageReady=0;
redxeth 0:6432166d0781 139 TERMINAL_PRINTF("\r\n");
redxeth 0:6432166d0781 140 TERMINAL_PRINTF("L:");
redxeth 0:6432166d0781 141
redxeth 0:6432166d0781 142 if(t==0)
redxeth 0:6432166d0781 143 t=4;
redxeth 0:6432166d0781 144 else
redxeth 0:6432166d0781 145 t--;
redxeth 0:6432166d0781 146
redxeth 0:6432166d0781 147 TFC_SetBatteryLED_Level(t);
redxeth 0:6432166d0781 148
redxeth 0:6432166d0781 149 // camera 1
redxeth 0:6432166d0781 150 for(i=0;i<128;i++)
redxeth 0:6432166d0781 151 {
redxeth 0:6432166d0781 152 TERMINAL_PRINTF("%X,",TFC_LineScanImage0[i]);
redxeth 0:6432166d0781 153 }
redxeth 0:6432166d0781 154
redxeth 0:6432166d0781 155 // camera 2
redxeth 0:6432166d0781 156 for(i=0;i<128;i++)
redxeth 0:6432166d0781 157 {
redxeth 0:6432166d0781 158 if(i==127)
redxeth 0:6432166d0781 159 TERMINAL_PRINTF("%X\r\n",TFC_LineScanImage1[i]);
redxeth 0:6432166d0781 160 else
redxeth 0:6432166d0781 161 TERMINAL_PRINTF("%X,",TFC_LineScanImage1[i]);
redxeth 0:6432166d0781 162
redxeth 0:6432166d0781 163 }
redxeth 0:6432166d0781 164 }
redxeth 0:6432166d0781 165
redxeth 0:6432166d0781 166 break;
redxeth 0:6432166d0781 167 }
redxeth 0:6432166d0781 168 }
redxeth 0:6432166d0781 169
redxeth 0:6432166d0781 170
redxeth 0:6432166d0781 171 }
redxeth 0:6432166d0781 172