Updated TFC library to be compatible with the recent hardware changes. Currently only CCD1, Servo1, Motor1, and Motor2 are interfaced.
Dependents: TFC-TEST_UPDATED_HW
Fork of FRDM-TFC by
Revision 9:9c61b6ebc028, committed 2018-01-12
- Comitter:
- alejandroRL
- Date:
- Fri Jan 12 18:22:35 2018 +0000
- Parent:
- 6:fbc2ba3c670a
- Commit message:
- Updated TFC library to be compatible with the new hardware changes.
Changed in this revision
diff -r fbc2ba3c670a -r 9c61b6ebc028 TFC.cpp --- a/TFC.cpp Tue Apr 15 02:36:19 2014 +0000 +++ b/TFC.cpp Fri Jan 12 18:22:35 2018 +0000 @@ -4,20 +4,19 @@ #define FTM1_CLK_PRESCALE 6// Prescale Selector value - see comments in Status Control (SC) section for more details #define SERVO_DEFAULT_PERIOD (float)(.020) // Desired Frequency of PWM Signal - Here 50Hz => 20ms period // use these to dial in servo steering to your particular servo -#define SERVO_MIN_PULSE_WIDTH_DEFAULT (float)(.0005) // The number here should be be *pulse width* in seconds to move servo to its left limit -#define SERVO_MAX_PULSE_WIDTH_DEFAULT (float)(.002) // The number here should be be *pulse width* in seconds to move servo to its left limit - +#define SERVO_MIN_PULSE_WIDTH_DEFAULT (float)0.0011 // The number here should be be *pulse width* in seconds to move servo to its right limit +#define SERVO_MAX_PULSE_WIDTH_DEFAULT (float)0.00148 // The number here should be be *pulse width* in seconds to move servo to its left limit #define FTM0_CLOCK (SystemCoreClock/2) #define FTM0_CLK_PRESCALE (0) // Prescale Selector value - see comments in Status Control (SC) section for more details -#define FTM0_DEFAULT_SWITCHING_FREQUENCY (4000.0) +#define FTM0_DEFAULT_SWITCHING_FREQUENCY (4000.0) #define ADC_MAX_CODE (4095) -#define TAOS_CLK_HIGH PTE->PSOR = (1<<1) -#define TAOS_CLK_LOW PTE->PCOR = (1<<1) -#define TAOS_SI_HIGH PTD->PSOR = (1<<7) -#define TAOS_SI_LOW PTD->PCOR = (1<<7) +#define TAOS_CLK_HIGH PTB->PSOR = (1<<9) +#define TAOS_CLK_LOW PTB->PCOR = (1<<9) +#define TAOS_SI_HIGH PTB->PSOR = (1<<8) +#define TAOS_SI_LOW PTB->PCOR = (1<<8) #define ADC_STATE_INIT 0 #define ADC_STATE_CAPTURE_POT_0 1 @@ -29,8 +28,8 @@ #define TFC_POT_0_ADC_CHANNEL 13 #define TFC_POT_1_ADC_CHANNEL 12 #define TFC_BAT_SENSE_CHANNEL 4 -#define TFC_LINESCAN0_ADC_CHANNEL 6 -#define TFC_LINESCAN1_ADC_CHANNEL 7 +#define TFC_LINESCAN0_ADC_CHANNEL 11 +#define TFC_LINESCAN1_ADC_CHANNEL 15 #define ADC0_irq_no 57 @@ -383,80 +382,8 @@ void TFC_GPIO_Init() { - //enable Clocks to all ports - SIM->SCGC5 |= SIM_SCGC5_PORTA_MASK | SIM_SCGC5_PORTB_MASK | SIM_SCGC5_PORTC_MASK | SIM_SCGC5_PORTD_MASK | SIM_SCGC5_PORTE_MASK; - - //Setup Pins as GPIO - PORTE->PCR[21] = PORT_PCR_MUX(1) | PORT_PCR_DSE_MASK; - PORTE->PCR[20] = PORT_PCR_MUX(1); - - //Port for Pushbuttons - PORTC->PCR[13] = PORT_PCR_MUX(1); - PORTC->PCR[17] = PORT_PCR_MUX(1); - - - //Ports for DIP Switches - PORTE->PCR[2] = PORT_PCR_MUX(1); - PORTE->PCR[3] = PORT_PCR_MUX(1); - PORTE->PCR[4] = PORT_PCR_MUX(1); - PORTE->PCR[5] = PORT_PCR_MUX(1); - - //Ports for LEDs - PORTB->PCR[8] = PORT_PCR_MUX(1) | PORT_PCR_DSE_MASK; - PORTB->PCR[9] = PORT_PCR_MUX(1) | PORT_PCR_DSE_MASK; - PORTB->PCR[10] = PORT_PCR_MUX(1) | PORT_PCR_DSE_MASK; - PORTB->PCR[11] = PORT_PCR_MUX(1) | PORT_PCR_DSE_MASK; - - - //Setup the output pins - PTE->PDDR = TFC_HBRIDGE_EN_LOC; - PTB->PDDR = TFC_BAT_LED0_LOC | TFC_BAT_LED1_LOC | TFC_BAT_LED2_LOC | TFC_BAT_LED3_LOC; - - TFC_SetBatteryLED(0); - TFC_HBRIDGE_DISABLE; -} - -void TFC_SetBatteryLED(uint8_t Value) -{ - if(Value & 0x01) - TFC_BAT_LED0_ON; - else - TFC_BAT_LED0_OFF; - - if(Value & 0x02) - TFC_BAT_LED1_ON; - else - TFC_BAT_LED1_OFF; - - if(Value & 0x04) - TFC_BAT_LED2_ON; - else - TFC_BAT_LED2_OFF; - - if(Value & 0x08) - TFC_BAT_LED3_ON; - else - TFC_BAT_LED3_OFF; -} - -uint8_t TFC_GetDIP_Switch() -{ - uint8_t DIP_Val=0; - - DIP_Val = (PTE->PDIR>>2) & 0xF; - - return DIP_Val; -} - -uint8_t TFC_ReadPushButton(uint8_t Index) -{ - if(Index == 0) { - return TFC_PUSH_BUTTON_0_PRESSED; - } else { - return TFC_PUSH_BUTTON_1_PRESSED; - } } extern "C" void TPM1_IRQHandler() @@ -488,7 +415,7 @@ void TFC_InitServos(float PulseWidthMin, float PulseWidthMax, float ServoPeriod) { - SIM->SCGC5 |= SIM_SCGC5_PORTB_MASK; + SIM->SCGC5 |= SIM_SCGC5_PORTA_MASK; _ServoPeriod = ServoPeriod; _ServoDutyCycleMin = PulseWidthMin/ServoPeriod; @@ -540,8 +467,8 @@ //Enable the FTM functions on the the port - PORTB->PCR[0] = PORT_PCR_MUX(3); - PORTB->PCR[1] = PORT_PCR_MUX(3); + PORTA->PCR[12] = PORT_PCR_MUX(3); + PORTA->PCR[13] = PORT_PCR_MUX(3); } @@ -876,16 +803,15 @@ void TFC_InitLineScanCamera() { - SIM->SCGC5 |= SIM_SCGC5_PORTE_MASK | SIM_SCGC5_PORTD_MASK; //Make sure the clock is enabled for PORTE; - PORTE->PCR[1] = PORT_PCR_MUX(1) | PORT_PCR_DSE_MASK; //Enable GPIO on on the pin for the CLOCK Signal - PORTD->PCR[7] = PORT_PCR_MUX(1) | PORT_PCR_DSE_MASK; //Enable GPIO on on the pin for SI signal - - PORTD->PCR[5] = PORT_PCR_MUX(0); //Make sure AO signal goes to an analog input - PORTD->PCR[6] = PORT_PCR_MUX(0); //Make sure AO signal goes to an analog input + SIM->SCGC5 |= SIM_SCGC5_PORTB_MASK | SIM_SCGC5_PORTC_MASK; //Make sure the clock is enabled for PORTE; + //Set pins for CCD0 + PORTB->PCR[9] = PORT_PCR_MUX(1) | PORT_PCR_DSE_MASK; //Enable GPIO on on the pin for the CLOCK Signal + PORTB->PCR[8] = PORT_PCR_MUX(1) | PORT_PCR_DSE_MASK; //Enable GPIO on on the pin for SI signal + PORTC->PCR[2] = PORT_PCR_MUX(0); //Make sure AO signal goes to an analog input //Make sure the Clock and SI pins are outputs - PTD->PDDR |= (1<<7); - PTE->PDDR |= (1<<1); + PTB->PDDR |= (1<<8); + PTB->PDDR |= (1<<9); TAOS_CLK_LOW; TAOS_SI_LOW; @@ -896,7 +822,7 @@ LineScanImage1WorkingBuffer = &LineScanImage1Buffer[LineScanWorkingBuffer][0]; TFC_LineScanImage0 = &LineScanImage0Buffer[1][0]; - TFC_LineScanImage1 = &LineScanImage1Buffer[1][0]; + TFC_LineScanImage1 = &LineScanImage1Buffer[1][0]; } @@ -913,8 +839,8 @@ //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_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) @@ -929,18 +855,16 @@ TPM0->CONF = 0; //While the counter is disabled we can setup the prescaler - TPM0->SC = TPM_SC_PS(FTM0_CLK_PRESCALE); //Setup the mod register to get the correct PWM Period - TPM0->MOD = (uint32_t)((float)(FTM0_CLOCK/(1<<FTM0_CLK_PRESCALE))/SwitchingFrequency); - //Setup Channels 0,1,2,3 - TPM0->CONTROLS[0].CnSC = TPM_CnSC_MSB_MASK | TPM_CnSC_ELSB_MASK; - TPM0->CONTROLS[1].CnSC = TPM_CnSC_MSB_MASK | TPM_CnSC_ELSA_MASK; // invert the second PWM signal for a complimentary output; - TPM0->CONTROLS[2].CnSC = TPM_CnSC_MSB_MASK | TPM_CnSC_ELSB_MASK; - TPM0->CONTROLS[3].CnSC = TPM_CnSC_MSB_MASK | TPM_CnSC_ELSA_MASK; // invert the second PWM signal for a complimentary output; + //Setup Channels 1,2,4,5 + TPM0->CONTROLS[1].CnSC = TPM_CnSC_MSB_MASK | TPM_CnSC_ELSB_MASK; + TPM0->CONTROLS[2].CnSC = TPM_CnSC_MSB_MASK | TPM_CnSC_ELSA_MASK; // invert the second PWM signal for a complimentary output; + TPM0->CONTROLS[4].CnSC = TPM_CnSC_MSB_MASK | TPM_CnSC_ELSB_MASK; + TPM0->CONTROLS[5].CnSC = TPM_CnSC_MSB_MASK | TPM_CnSC_ELSA_MASK; // invert the second PWM signal for a complimentary output; //Enable the Counter @@ -951,10 +875,10 @@ TPM0->SC |= TPM_SC_CMOD(1); //Enable the FTM functions on the the port - PORTC->PCR[1] = PORT_PCR_MUX(4); - PORTC->PCR[2] = PORT_PCR_MUX(4); - PORTC->PCR[3] = PORT_PCR_MUX(4); - PORTC->PCR[4] = PORT_PCR_MUX(4); + PORTA->PCR[4] = PORT_PCR_MUX(3); //FTM0_CH1 + PORTA->PCR[5] = PORT_PCR_MUX(3); //FTM0_CH2 + PORTC->PCR[8] = PORT_PCR_MUX(3); //FTM0_CH4 + PORTC->PCR[9] = PORT_PCR_MUX(3); //FTM0_CH5 } @@ -970,67 +894,9 @@ else if(MotorB<-1.0) MotorB = -1.0; - TPM0->CONTROLS[2].CnV = (uint16_t) ((float)TPM0->MOD * (float)((MotorA + 1.0)/2.0)); - TPM0->CONTROLS[3].CnV = TPM0->CONTROLS[2].CnV; - TPM0->CONTROLS[0].CnV = (uint16_t) ((float)TPM0->MOD * (float)((MotorB + 1.0)/2.0)); - TPM0->CONTROLS[1].CnV = TPM0->CONTROLS[0].CnV; + TPM0->CONTROLS[1].CnV = (uint16_t) ((float)TPM0->MOD * (float)((MotorA + 1.0)/2.0)); + TPM0->CONTROLS[2].CnV = TPM0->CONTROLS[1].CnV; + TPM0->CONTROLS[4].CnV = (uint16_t) ((float)TPM0->MOD * (float)((MotorB + 1.0)/2.0)); + TPM0->CONTROLS[5].CnV = TPM0->CONTROLS[4].CnV; } - -//Pot Reading is Scaled to return a value of -1.0 to 1.0 -float TFC_ReadPot(uint8_t Channel) -{ - if(Channel == 0) - return ((float)PotADC_Value[0]/-((float)ADC_MAX_CODE/2.0))+1.0; - else - return ((float)PotADC_Value[1]/-((float)ADC_MAX_CODE/2.0))+1.0; -} - -float TFC_ReadBatteryVoltage() -{ - 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; - - } -}
diff -r fbc2ba3c670a -r 9c61b6ebc028 TFC.h --- a/TFC.h Tue Apr 15 02:36:19 2014 +0000 +++ b/TFC.h Fri Jan 12 18:22:35 2018 +0000 @@ -21,38 +21,19 @@ I/O:\n -------------------------------------------------------------------------------------------------\n - PTB0 (Servo Channel 0 - TPM1)\n - PTB1 (Servo Channel 1 - TPM1)\n + PTA12 Servo 1\n + PTA13 Servo 2\n \n - PTB8 (Battery LED0)\n - PTB9 (Battery LED1)\n - PTB10 (Battery LED2)\n - PTB11 (Battery LED3)\n -\n - PTD7 (Camera SI)\n - PTE0 (Camera CLK)\n - PTD5 (Camera A0 - ADC_SE6b)\n - PTD6 (Camera A1 - ADC_SE7b)\n \n - PTE2 DIP Switch 0\n - PTE3 DIP Switch 1\n - PTE4 DIP Switch 2\n - PTE5 DIP Switch 3\n - - PTC13 Pushbutton SW1\n - PTC17 Pushbutton SW2\n + PTB8 (Camera CCD1 SI)\n + PTB9 (Camera CCD1 CLK)\n + PTC2 (Camera CCD1 A0)\n +\n - PTC3 H-Bridge A - 1 FTM0_CH3\n - PTC4 H-Bridge A - 2 FTM0_CH4\n - PTC1 H-Bridge B - 1 FTM0_CH1\n - PTC2 H-Bridge B - 2 FTM0_CH2\n - - PTE21 H-Bridge Enable\n - PTE20 H-Bridge Fault\n - - PTE23 H-Bridge A - IFB\n - PTE22 H-Bridge B - IFB\n - + PTA4 Motor1 PWM1 FTM0_CH1\n + PTA5 Motor1 PWM2 FTM0_CH2\n + PTC8 Motor2 PWM1 FTM0_CH4\n + PTC9 Motor2 PWM2 FTM0_CH5\n } */ @@ -61,29 +42,10 @@ #ifndef _TFC_H #define _TFC_H -#define TFC_HBRIDGE_EN_LOC (uint32_t)(1<<21) -#define TFC_HBRIDGE_FAULT_LOC (uint32_t)(1<<20) - -#define TFC_HBRIDGE_ENABLE PTE->PSOR = TFC_HBRIDGE_EN_LOC -#define TFC_HBRIDGE_DISABLE PTE->PCOR = TFC_HBRIDGE_EN_LOC - -#define TFC_DIP_SWITCH0_LOC ((uint32_t)(1<<2)) -#define TFC_DIP_SWITCH1_LOC ((uint32_t)(1<<3)) -#define TFC_DIP_SWITCH2_LOC ((uint32_t)(1<<4)) -#define TFC_DIP_SWITCH3_LOC ((uint32_t)(1<<5)) - -#define TFC_PUSH_BUTT0N0_LOC ((uint32_t)(1<<13)) -#define TFC_PUSH_BUTT0N1_LOC ((uint32_t)(1<<17)) - -#define TFC_BAT_LED0_LOC ((uint32_t)(1<<11)) -#define TFC_BAT_LED1_LOC ((uint32_t)(1<<10)) -#define TFC_BAT_LED2_LOC ((uint32_t)(1<<9)) -#define TFC_BAT_LED3_LOC ((uint32_t)(1<<8)) - -#define TAOS_CLK_HIGH PTE->PSOR = (1<<1) -#define TAOS_CLK_LOW PTE->PCOR = (1<<1) -#define TAOS_SI_HIGH PTD->PSOR = (1<<7) -#define TAOS_SI_LOW PTD->PCOR = (1<<7) +#define TAOS_CLK_HIGH PTB->PSOR = (1<<9) +#define TAOS_CLK_LOW PTB->PCOR = (1<<9) +#define TAOS_SI_HIGH PTB->PSOR = (1<<8) +#define TAOS_SI_LOW PTB->PCOR = (1<<8) /** @@ -92,54 +54,6 @@ @{ */ -/**Macro to turn on LED 0 in the battery indicator array*/ -#define TFC_BAT_LED0_ON PTB->PSOR = TFC_BAT_LED0_LOC -/** Macro to turn on LED 1 in the battery indicator array*/ -#define TFC_BAT_LED1_ON PTB->PSOR = TFC_BAT_LED1_LOC -/** Macro to turn on LED 2 in the battery indicator array*/ -#define TFC_BAT_LED2_ON PTB->PSOR = TFC_BAT_LED2_LOC -/** Macro to turn on LED 3 in the battery indicator array*/ -#define TFC_BAT_LED3_ON PTB->PSOR = TFC_BAT_LED3_LOC - - -/** Macro to turn off LED 0 in the battery indicator array*/ -#define TFC_BAT_LED0_OFF PTB->PCOR = TFC_BAT_LED0_LOC -/** Macro to turn off LED 1 in the battery indicator array*/ -#define TFC_BAT_LED1_OFF PTB->PCOR = TFC_BAT_LED1_LOC -/** Macro to turn off LED 2 in the battery indicator array*/ -#define TFC_BAT_LED2_OFF PTB->PCOR = TFC_BAT_LED2_LOC -/** Macro to turn off LED 3 in the battery indicator array*/ -#define TFC_BAT_LED3_OFF PTB->PCOR = TFC_BAT_LED3_LOC - - -/** Macro to toggle LED 0 in the battery indicator array*/ -#define TFC_BAT_LED0_TOGGLE PTB->PTOR = TFC_BAT_LED0_LOC -/** Macro to toggle LED 1 in the battery indicator array*/ -#define TFC_BAT_LED1_TOGGLE PTB->PTOR = TFC_BAT_LED1_LOC -/** Macro to toggle LED 2 in the battery indicator array*/ -#define TFC_BAT_LED2_TOGGLE PTB->PTOR = TFC_BAT_LED2_LOC -/** Macro to toggle LED 3 in the battery indicator array*/ -#define TFC_BAT_LED3_TOGGLE PTB->PTOR = TFC_BAT_LED3_LOC - - -/** Macro to read the state of the pushbutton SW1*/ -#define TFC_PUSH_BUTTON_0_PRESSED ((PTC->PDIR&TFC_PUSH_BUTT0N0_LOC)>0) -/** Macro to read the state of the pushbutton SW1*/ -#define TFC_PUSH_BUTTON_1_PRESSED ((PTC->PDIR&TFC_PUSH_BUTT0N1_LOC)>0) - -/** Macro to read the state of switch 0 in the 4 position DIP switch*/ -#define TFC_DIP_SWITCH_0_ON ((TFC_GetDIP_Switch()&0x01)>0) - -/** Macro to read the state of switch 1 in the 4 position DIP switch*/ -#define TFC_DIP_SWITCH_1_ON ((TFC_GetDIP_Switch()&0x02)>0) - -/** Macro to read the state of switch 2 in the 4 position DIP switch*/ -#define TFC_DIP_SWITCH_2_ON ((TFC_GetDIP_Switch()&0x04)>0) - -/** Macro to read the state of switch 3 in the 4 position DIP switch*/ -#define TFC_DIP_SWITCH_3_ON ((TFC_GetDIP_Switch()&0x08)>0) - - /** Initialized the TFC API. Call before using any other API calls. * */ @@ -152,27 +66,6 @@ extern volatile uint32_t TFC_ServoTicker; -/** Gets the state of the 4-positiomn DIP switch on the FRDM-TFC -* -* @returns The lower 4-bits of the return value map to the 4-bits of the DIP switch -*/ -uint8_t TFC_GetDIP_Switch(); - - -/** Reads the state of the pushbuttons (SW1, SW2) on the FRDM-TFC -* @param Index Selects the pushbutton (0 for SW1 and 1 for SW2) -* @returns A non-zero value if the button is pushed -*/ -uint8_t TFC_ReadPushButton(uint8_t Index); - - -/** Controls the 4 battery level LEDs on the FRDM-TFC boards. -* -* @param Value The lower 4-bits of the parameter maps to the 4 LEDs. -*/ -void TFC_SetBatteryLED(uint8_t Value); - - /** Sets the servo channels * * @param ServoNumber Which servo channel on the FRDM-TFC to use (0 or 1). 0 is the default channel for steering @@ -204,28 +97,6 @@ */ void TFC_SetMotorPWM(float MotorA ,float MotorB); -/** Reads the potentiometers -* -* @param Channel Selects which pot is read. I.e. 0 for POT0 or 1 for POT1 -* @returns Pot value from -1.0 to 1.0 -*/ -float TFC_ReadPot(uint8_t Channel); - -/** Gets the current battery voltage -* -* @returns Battery voltage in floating point form. -*/ -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. @@ -242,10 +113,6 @@ extern volatile uint8_t TFC_LineScanImageReady; - - - - /** @} */
diff -r fbc2ba3c670a -r 9c61b6ebc028 mbed.bld --- a/mbed.bld Tue Apr 15 02:36:19 2014 +0000 +++ b/mbed.bld Fri Jan 12 18:22:35 2018 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/mbed_official/code/mbed/builds/5798e58a58b1 \ No newline at end of file +http://mbed.org/users/mbed_official/code/mbed/builds/7130f322cb7e \ No newline at end of file