![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Our version of TFC code.
Fork of FRDM-TFC by
TFC.h@3:23cce037011f, 2013-08-15 (annotated)
- Committer:
- emh203
- Date:
- Thu Aug 15 23:26:19 2013 +0000
- Revision:
- 3:23cce037011f
- Parent:
- 1:6f37253dab87
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.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
emh203 | 1:6f37253dab87 | 1 | |
emh203 | 1:6f37253dab87 | 2 | #include "mbed.h" |
emh203 | 1:6f37253dab87 | 3 | |
emh203 | 1:6f37253dab87 | 4 | /** @file test.h*/ |
emh203 | 1:6f37253dab87 | 5 | |
emh203 | 1:6f37253dab87 | 6 | /** |
emh203 | 1:6f37253dab87 | 7 | * @defgroup FRDM-TFC_API FRDM-TFC_API |
emh203 | 1:6f37253dab87 | 8 | * |
emh203 | 1:6f37253dab87 | 9 | * @{ |
emh203 | 1:6f37253dab87 | 10 | */ |
emh203 | 1:6f37253dab87 | 11 | |
emh203 | 1:6f37253dab87 | 12 | |
emh203 | 1:6f37253dab87 | 13 | /** |
emh203 | 1:6f37253dab87 | 14 | |
emh203 | 1:6f37253dab87 | 15 | @addtogroup FRDM-TFC_API |
emh203 | 1:6f37253dab87 | 16 | |
emh203 | 1:6f37253dab87 | 17 | @{ |
emh203 | 1:6f37253dab87 | 18 | |
emh203 | 1:6f37253dab87 | 19 | Resources used by the TFC Library\n |
emh203 | 1:6f37253dab87 | 20 | |
emh203 | 1:6f37253dab87 | 21 | I/O:\n |
emh203 | 1:6f37253dab87 | 22 | -------------------------------------------------------------------------------------------------\n |
emh203 | 1:6f37253dab87 | 23 | |
emh203 | 1:6f37253dab87 | 24 | PTB0 (Servo Channel 0 - TPM1)\n |
emh203 | 1:6f37253dab87 | 25 | PTB1 (Servo Channel 1 - TPM1)\n |
emh203 | 1:6f37253dab87 | 26 | \n |
emh203 | 1:6f37253dab87 | 27 | PTB8 (Battery LED0)\n |
emh203 | 1:6f37253dab87 | 28 | PTB9 (Battery LED1)\n |
emh203 | 1:6f37253dab87 | 29 | PTB10 (Battery LED2)\n |
emh203 | 1:6f37253dab87 | 30 | PTB11 (Battery LED3)\n |
emh203 | 1:6f37253dab87 | 31 | \n |
emh203 | 1:6f37253dab87 | 32 | PTD7 (Camera SI)\n |
emh203 | 1:6f37253dab87 | 33 | PTE0 (Camera CLK)\n |
emh203 | 1:6f37253dab87 | 34 | PTD5 (Camera A0 - ADC_SE6b)\n |
emh203 | 1:6f37253dab87 | 35 | PTD6 (Camera A1 - ADC_SE7b)\n |
emh203 | 1:6f37253dab87 | 36 | \n |
emh203 | 1:6f37253dab87 | 37 | PTE2 DIP Switch 0\n |
emh203 | 1:6f37253dab87 | 38 | PTE3 DIP Switch 1\n |
emh203 | 1:6f37253dab87 | 39 | PTE4 DIP Switch 2\n |
emh203 | 1:6f37253dab87 | 40 | PTE5 DIP Switch 3\n |
emh203 | 1:6f37253dab87 | 41 | |
emh203 | 1:6f37253dab87 | 42 | PTC13 Pushbutton SW1\n |
emh203 | 1:6f37253dab87 | 43 | PTC17 Pushbutton SW2\n |
emh203 | 1:6f37253dab87 | 44 | |
emh203 | 1:6f37253dab87 | 45 | PTC3 H-Bridge A - 1 FTM0_CH3\n |
emh203 | 1:6f37253dab87 | 46 | PTC4 H-Bridge A - 2 FTM0_CH4\n |
emh203 | 1:6f37253dab87 | 47 | PTC1 H-Bridge B - 1 FTM0_CH1\n |
emh203 | 1:6f37253dab87 | 48 | PTC2 H-Bridge B - 2 FTM0_CH2\n |
emh203 | 1:6f37253dab87 | 49 | |
emh203 | 1:6f37253dab87 | 50 | PTE21 H-Bridge Enable\n |
emh203 | 1:6f37253dab87 | 51 | PTE20 H-Bridge Fault\n |
emh203 | 1:6f37253dab87 | 52 | |
emh203 | 1:6f37253dab87 | 53 | PTE23 H-Bridge A - IFB\n |
emh203 | 1:6f37253dab87 | 54 | PTE22 H-Bridge B - IFB\n |
emh203 | 1:6f37253dab87 | 55 | |
emh203 | 1:6f37253dab87 | 56 | } |
emh203 | 1:6f37253dab87 | 57 | */ |
emh203 | 1:6f37253dab87 | 58 | |
emh203 | 1:6f37253dab87 | 59 | |
emh203 | 1:6f37253dab87 | 60 | |
emh203 | 1:6f37253dab87 | 61 | #ifndef _TFC_H |
emh203 | 1:6f37253dab87 | 62 | #define _TFC_H |
emh203 | 1:6f37253dab87 | 63 | |
emh203 | 1:6f37253dab87 | 64 | #define TFC_HBRIDGE_EN_LOC (uint32_t)(1<<21) |
emh203 | 1:6f37253dab87 | 65 | #define TFC_HBRIDGE_FAULT_LOC (uint32_t)(1<<20) |
emh203 | 1:6f37253dab87 | 66 | |
emh203 | 1:6f37253dab87 | 67 | #define TFC_HBRIDGE_ENABLE PTE->PSOR = TFC_HBRIDGE_EN_LOC |
emh203 | 1:6f37253dab87 | 68 | #define TFC_HBRIDGE_DISABLE PTE->PCOR = TFC_HBRIDGE_EN_LOC |
emh203 | 1:6f37253dab87 | 69 | |
emh203 | 1:6f37253dab87 | 70 | #define TFC_DIP_SWITCH0_LOC ((uint32_t)(1<<2)) |
emh203 | 1:6f37253dab87 | 71 | #define TFC_DIP_SWITCH1_LOC ((uint32_t)(1<<3)) |
emh203 | 1:6f37253dab87 | 72 | #define TFC_DIP_SWITCH2_LOC ((uint32_t)(1<<4)) |
emh203 | 1:6f37253dab87 | 73 | #define TFC_DIP_SWITCH3_LOC ((uint32_t)(1<<5)) |
emh203 | 1:6f37253dab87 | 74 | |
emh203 | 1:6f37253dab87 | 75 | #define TFC_PUSH_BUTT0N0_LOC ((uint32_t)(1<<13)) |
emh203 | 1:6f37253dab87 | 76 | #define TFC_PUSH_BUTT0N1_LOC ((uint32_t)(1<<17)) |
emh203 | 1:6f37253dab87 | 77 | |
emh203 | 1:6f37253dab87 | 78 | #define TFC_BAT_LED0_LOC ((uint32_t)(1<<11)) |
emh203 | 1:6f37253dab87 | 79 | #define TFC_BAT_LED1_LOC ((uint32_t)(1<<10)) |
emh203 | 1:6f37253dab87 | 80 | #define TFC_BAT_LED2_LOC ((uint32_t)(1<<9)) |
emh203 | 1:6f37253dab87 | 81 | #define TFC_BAT_LED3_LOC ((uint32_t)(1<<8)) |
emh203 | 1:6f37253dab87 | 82 | |
emh203 | 1:6f37253dab87 | 83 | #define TAOS_CLK_HIGH PTE->PSOR = (1<<1) |
emh203 | 1:6f37253dab87 | 84 | #define TAOS_CLK_LOW PTE->PCOR = (1<<1) |
emh203 | 1:6f37253dab87 | 85 | #define TAOS_SI_HIGH PTD->PSOR = (1<<7) |
emh203 | 1:6f37253dab87 | 86 | #define TAOS_SI_LOW PTD->PCOR = (1<<7) |
emh203 | 1:6f37253dab87 | 87 | |
emh203 | 1:6f37253dab87 | 88 | |
emh203 | 1:6f37253dab87 | 89 | /** |
emh203 | 1:6f37253dab87 | 90 | |
emh203 | 1:6f37253dab87 | 91 | @addtogroup FRDM-TFC_API |
emh203 | 1:6f37253dab87 | 92 | @{ |
emh203 | 1:6f37253dab87 | 93 | */ |
emh203 | 1:6f37253dab87 | 94 | |
emh203 | 1:6f37253dab87 | 95 | /**Macro to turn on LED 0 in the battery indicator array*/ |
emh203 | 1:6f37253dab87 | 96 | #define TFC_BAT_LED0_ON PTB->PSOR = TFC_BAT_LED0_LOC |
emh203 | 1:6f37253dab87 | 97 | /** Macro to turn on LED 1 in the battery indicator array*/ |
emh203 | 1:6f37253dab87 | 98 | #define TFC_BAT_LED1_ON PTB->PSOR = TFC_BAT_LED1_LOC |
emh203 | 1:6f37253dab87 | 99 | /** Macro to turn on LED 2 in the battery indicator array*/ |
emh203 | 1:6f37253dab87 | 100 | #define TFC_BAT_LED2_ON PTB->PSOR = TFC_BAT_LED2_LOC |
emh203 | 1:6f37253dab87 | 101 | /** Macro to turn on LED 3 in the battery indicator array*/ |
emh203 | 1:6f37253dab87 | 102 | #define TFC_BAT_LED3_ON PTB->PSOR = TFC_BAT_LED3_LOC |
emh203 | 1:6f37253dab87 | 103 | |
emh203 | 1:6f37253dab87 | 104 | |
emh203 | 1:6f37253dab87 | 105 | /** Macro to turn off LED 0 in the battery indicator array*/ |
emh203 | 1:6f37253dab87 | 106 | #define TFC_BAT_LED0_OFF PTB->PCOR = TFC_BAT_LED0_LOC |
emh203 | 1:6f37253dab87 | 107 | /** Macro to turn off LED 1 in the battery indicator array*/ |
emh203 | 1:6f37253dab87 | 108 | #define TFC_BAT_LED1_OFF PTB->PCOR = TFC_BAT_LED1_LOC |
emh203 | 1:6f37253dab87 | 109 | /** Macro to turn off LED 2 in the battery indicator array*/ |
emh203 | 1:6f37253dab87 | 110 | #define TFC_BAT_LED2_OFF PTB->PCOR = TFC_BAT_LED2_LOC |
emh203 | 1:6f37253dab87 | 111 | /** Macro to turn off LED 3 in the battery indicator array*/ |
emh203 | 1:6f37253dab87 | 112 | #define TFC_BAT_LED3_OFF PTB->PCOR = TFC_BAT_LED3_LOC |
emh203 | 1:6f37253dab87 | 113 | |
emh203 | 1:6f37253dab87 | 114 | |
emh203 | 1:6f37253dab87 | 115 | /** Macro to toggle LED 0 in the battery indicator array*/ |
emh203 | 1:6f37253dab87 | 116 | #define TFC_BAT_LED0_TOGGLE PTB->PTOR = TFC_BAT_LED0_LOC |
emh203 | 1:6f37253dab87 | 117 | /** Macro to toggle LED 1 in the battery indicator array*/ |
emh203 | 1:6f37253dab87 | 118 | #define TFC_BAT_LED1_TOGGLE PTB->PTOR = TFC_BAT_LED1_LOC |
emh203 | 1:6f37253dab87 | 119 | /** Macro to toggle LED 2 in the battery indicator array*/ |
emh203 | 1:6f37253dab87 | 120 | #define TFC_BAT_LED2_TOGGLE PTB->PTOR = TFC_BAT_LED2_LOC |
emh203 | 1:6f37253dab87 | 121 | /** Macro to toggle LED 3 in the battery indicator array*/ |
emh203 | 1:6f37253dab87 | 122 | #define TFC_BAT_LED3_TOGGLE PTB->PTOR = TFC_BAT_LED3_LOC |
emh203 | 1:6f37253dab87 | 123 | |
emh203 | 1:6f37253dab87 | 124 | |
emh203 | 1:6f37253dab87 | 125 | /** Macro to read the state of the pushbutton SW1*/ |
emh203 | 1:6f37253dab87 | 126 | #define TFC_PUSH_BUTTON_0_PRESSED ((PTC->PDIR&TFC_PUSH_BUTT0N0_LOC)>0) |
emh203 | 1:6f37253dab87 | 127 | /** Macro to read the state of the pushbutton SW1*/ |
emh203 | 1:6f37253dab87 | 128 | #define TFC_PUSH_BUTTON_1_PRESSED ((PTC->PDIR&TFC_PUSH_BUTT0N1_LOC)>0) |
emh203 | 1:6f37253dab87 | 129 | |
emh203 | 1:6f37253dab87 | 130 | /** Macro to read the state of switch 0 in the 4 position DIP switch*/ |
emh203 | 1:6f37253dab87 | 131 | #define TFC_DIP_SWITCH_0_ON ((TFC_GetDIP_Switch()&0x01)>0) |
emh203 | 1:6f37253dab87 | 132 | |
emh203 | 1:6f37253dab87 | 133 | /** Macro to read the state of switch 1 in the 4 position DIP switch*/ |
emh203 | 1:6f37253dab87 | 134 | #define TFC_DIP_SWITCH_1_ON ((TFC_GetDIP_Switch()&0x02)>0) |
emh203 | 1:6f37253dab87 | 135 | |
emh203 | 1:6f37253dab87 | 136 | /** Macro to read the state of switch 2 in the 4 position DIP switch*/ |
emh203 | 1:6f37253dab87 | 137 | #define TFC_DIP_SWITCH_2_ON ((TFC_GetDIP_Switch()&0x04)>0) |
emh203 | 1:6f37253dab87 | 138 | |
emh203 | 1:6f37253dab87 | 139 | /** Macro to read the state of switch 3 in the 4 position DIP switch*/ |
emh203 | 1:6f37253dab87 | 140 | #define TFC_DIP_SWITCH_3_ON ((TFC_GetDIP_Switch()&0x08)>0) |
emh203 | 1:6f37253dab87 | 141 | |
emh203 | 1:6f37253dab87 | 142 | |
emh203 | 1:6f37253dab87 | 143 | /** Initialized the TFC API. Call before using any other API calls. |
emh203 | 1:6f37253dab87 | 144 | * |
emh203 | 1:6f37253dab87 | 145 | */ |
emh203 | 1:6f37253dab87 | 146 | void TFC_Init(); |
emh203 | 1:6f37253dab87 | 147 | |
emh203 | 1:6f37253dab87 | 148 | /** ServoTicker will increment once every servo cycle. |
emh203 | 1:6f37253dab87 | 149 | * It can be used to synchronize events to the start of a servo cycle. ServoTicker is a volatile uint32_t and is updated in the TPM1 overlflow interrupt. This means you will see ServoTicker increment on the rising edge of the servo PWM signal |
emh203 | 1:6f37253dab87 | 150 | * |
emh203 | 1:6f37253dab87 | 151 | */ |
emh203 | 1:6f37253dab87 | 152 | extern volatile uint32_t TFC_ServoTicker; |
emh203 | 1:6f37253dab87 | 153 | |
emh203 | 1:6f37253dab87 | 154 | |
emh203 | 1:6f37253dab87 | 155 | /** Gets the state of the 4-positiomn DIP switch on the FRDM-TFC |
emh203 | 1:6f37253dab87 | 156 | * |
emh203 | 1:6f37253dab87 | 157 | * @returns The lower 4-bits of the return value map to the 4-bits of the DIP switch |
emh203 | 1:6f37253dab87 | 158 | */ |
emh203 | 1:6f37253dab87 | 159 | uint8_t TFC_GetDIP_Switch(); |
emh203 | 1:6f37253dab87 | 160 | |
emh203 | 1:6f37253dab87 | 161 | |
emh203 | 1:6f37253dab87 | 162 | /** Reads the state of the pushbuttons (SW1, SW2) on the FRDM-TFC |
emh203 | 1:6f37253dab87 | 163 | * @param Index Selects the pushbutton (0 for SW1 and 1 for SW2) |
emh203 | 1:6f37253dab87 | 164 | * @returns A non-zero value if the button is pushed |
emh203 | 1:6f37253dab87 | 165 | */ |
emh203 | 1:6f37253dab87 | 166 | uint8_t TFC_ReadPushButton(uint8_t Index); |
emh203 | 1:6f37253dab87 | 167 | |
emh203 | 1:6f37253dab87 | 168 | |
emh203 | 1:6f37253dab87 | 169 | /** Controls the 4 battery level LEDs on the FRDM-TFC boards. |
emh203 | 1:6f37253dab87 | 170 | * |
emh203 | 1:6f37253dab87 | 171 | * @param Value The lower 4-bits of the parameter maps to the 4 LEDs. |
emh203 | 1:6f37253dab87 | 172 | */ |
emh203 | 1:6f37253dab87 | 173 | void TFC_SetBatteryLED(uint8_t Value); |
emh203 | 1:6f37253dab87 | 174 | |
emh203 | 1:6f37253dab87 | 175 | |
emh203 | 1:6f37253dab87 | 176 | /** Sets the servo channels |
emh203 | 1:6f37253dab87 | 177 | * |
emh203 | 1:6f37253dab87 | 178 | * @param ServoNumber Which servo channel on the FRDM-TFC to use (0 or 1). 0 is the default channel for steering |
emh203 | 1:6f37253dab87 | 179 | * @param Position Angle setting for servo in a normalized (-1.0 to 1.0) form. The range of the servo can be changed with the InitServos function. |
emh203 | 1:6f37253dab87 | 180 | * This is called in the TFC constructor with some useful default values--> 20mSec period, 0.5mS min and 2.0mSec max. you may need to adjust these for your own particular setup. |
emh203 | 1:6f37253dab87 | 181 | */ |
emh203 | 1:6f37253dab87 | 182 | void TFC_SetServo(uint8_t ServoNumber, float Position); |
emh203 | 1:6f37253dab87 | 183 | |
emh203 | 1:6f37253dab87 | 184 | /** Initializes TPM for the servoes. It also sets the max and min ranges |
emh203 | 1:6f37253dab87 | 185 | * |
emh203 | 1:6f37253dab87 | 186 | * @param ServoPulseWidthMin Minimum pulse width (in seconds) for the servo. The value of -1.0 in SetServo is mapped to this pulse width. I.E. .001 |
emh203 | 1:6f37253dab87 | 187 | * @param ServoPulseWidthMax Maximum pulse width (in seconds) for the servo. The value of +1.0 in SetServo is mapped to this pulse width. I.E. .002 |
emh203 | 1:6f37253dab87 | 188 | * @param ServoPeriod Period of the servo pulses (in seconds). I.e. .020 for 20mSec |
emh203 | 1:6f37253dab87 | 189 | */ |
emh203 | 1:6f37253dab87 | 190 | |
emh203 | 1:6f37253dab87 | 191 | void TFC_InitServos(float ServoPulseWidthMin, float ServoPulseWidthMax, float ServoPeriod); |
emh203 | 1:6f37253dab87 | 192 | |
emh203 | 1:6f37253dab87 | 193 | |
emh203 | 1:6f37253dab87 | 194 | /** Initialized TPM0 to be used for generating PWM signals for the the dual drive motors. This method is called in the TFC constructor with a default value of 4000.0Hz |
emh203 | 1:6f37253dab87 | 195 | * |
emh203 | 1:6f37253dab87 | 196 | * @param SwitchingFrequency PWM Switching Frequency in floating point format. Pick something between 1000 and 9000. Maybe you can modulate it and make a tune. |
emh203 | 1:6f37253dab87 | 197 | */ |
emh203 | 1:6f37253dab87 | 198 | void TFC_InitMotorPWM(float SwitchingFrequency); |
emh203 | 1:6f37253dab87 | 199 | |
emh203 | 1:6f37253dab87 | 200 | /** Sets the PWM value for each motor. |
emh203 | 1:6f37253dab87 | 201 | * |
emh203 | 1:6f37253dab87 | 202 | * @param MotorA The PWM value for HBridgeA. The value is normalized to the floating point range of -1.0 to +1.0. -1.0 is 0% (Full Reverse on the H-Bridge) and 1.0 is 100% (Full Forward on the H-Bridge) |
emh203 | 1:6f37253dab87 | 203 | * @param MotorB The PWM value for HBridgeB. The value is normalized to the floating point range of -1.0 to +1.0. -1.0 is 0% (Full Reverse on the H-Bridge) and 1.0 is 100% (Full Forward on the H-Bridge) |
emh203 | 1:6f37253dab87 | 204 | */ |
emh203 | 1:6f37253dab87 | 205 | void TFC_SetMotorPWM(float MotorA ,float MotorB); |
emh203 | 1:6f37253dab87 | 206 | |
emh203 | 1:6f37253dab87 | 207 | /** Reads the potentiometers |
emh203 | 1:6f37253dab87 | 208 | * |
emh203 | 1:6f37253dab87 | 209 | * @param Channel Selects which pot is read. I.e. 0 for POT0 or 1 for POT1 |
emh203 | 1:6f37253dab87 | 210 | * @returns Pot value from -1.0 to 1.0 |
emh203 | 1:6f37253dab87 | 211 | */ |
emh203 | 1:6f37253dab87 | 212 | float TFC_ReadPot(uint8_t Channel); |
emh203 | 1:6f37253dab87 | 213 | |
emh203 | 1:6f37253dab87 | 214 | /** Gets the current battery voltage |
emh203 | 1:6f37253dab87 | 215 | * |
emh203 | 1:6f37253dab87 | 216 | * @returns Battery voltage in floating point form. |
emh203 | 1:6f37253dab87 | 217 | */ |
emh203 | 1:6f37253dab87 | 218 | float TFC_ReadBatteryVoltage(); |
emh203 | 1:6f37253dab87 | 219 | |
emh203 | 1:6f37253dab87 | 220 | |
emh203 | 3:23cce037011f | 221 | |
emh203 | 3:23cce037011f | 222 | /** Sets the Battery level indiciate |
emh203 | 3:23cce037011f | 223 | * |
emh203 | 3:23cce037011f | 224 | * @param BattLevel A number betwween 0 and 4. This will light the bar from left to right with the specifified number of segments. |
emh203 | 3:23cce037011f | 225 | * |
emh203 | 3:23cce037011f | 226 | */ |
emh203 | 3:23cce037011f | 227 | void TFC_SetBatteryLED_Level(uint8_t BattLevel); |
emh203 | 3:23cce037011f | 228 | |
emh203 | 3:23cce037011f | 229 | |
emh203 | 1:6f37253dab87 | 230 | /** 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 |
emh203 | 1:6f37253dab87 | 231 | *inactive buffer. |
emh203 | 1:6f37253dab87 | 232 | * |
emh203 | 1:6f37253dab87 | 233 | */ |
emh203 | 1:6f37253dab87 | 234 | |
emh203 | 3:23cce037011f | 235 | extern volatile uint16_t * TFC_LineScanImage0; |
emh203 | 3:23cce037011f | 236 | extern volatile uint16_t * TFC_LineScanImage1; |
emh203 | 3:23cce037011f | 237 | |
emh203 | 1:6f37253dab87 | 238 | |
emh203 | 1:6f37253dab87 | 239 | /** 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) |
emh203 | 1:6f37253dab87 | 240 | * |
emh203 | 1:6f37253dab87 | 241 | */ |
emh203 | 1:6f37253dab87 | 242 | |
emh203 | 3:23cce037011f | 243 | extern volatile uint8_t TFC_LineScanImageReady; |
emh203 | 3:23cce037011f | 244 | |
emh203 | 3:23cce037011f | 245 | |
emh203 | 3:23cce037011f | 246 | |
emh203 | 1:6f37253dab87 | 247 | |
emh203 | 1:6f37253dab87 | 248 | |
emh203 | 1:6f37253dab87 | 249 | /** @} */ |
emh203 | 1:6f37253dab87 | 250 | |
emh203 | 1:6f37253dab87 | 251 | |
emh203 | 1:6f37253dab87 | 252 | #endif |