Other Parts Discussed in Thread: EK-TM4C1294XL
Hello all, I have a custom board that can control some fans and record their RPM's. The fans are controlled via PWM signals and they have a tachometer that are connected to several CCP pins on the boards. I will use Fan 1 which is connected to T0CCP1 for this question since all the other fans should be the same with different pins configured for them. Here is the code and circuitry I have so far.
Pin connection to the tachometer:
Fan tachometer output information.
Code to setup timer:
static void InitializeTimer0( uint32_t ui32SysClock ) { //Enable timer 0 peripheral SysCtlPeripheralEnable( SYSCTL_PERIPH_TIMER0 ); while(!SysCtlPeripheralReady( SYSCTL_PERIPH_TIMER0 )){ } //Enable GPIO A peripheral since the CCP pins are on there. SysCtlPeripheralEnable( SYSCTL_PERIPH_GPIOA ); while(!SysCtlPeripheralReady( SYSCTL_PERIPH_GPIOA )){ } //Configure the GPIO pins used for CCP operation. GPIOPinConfigure( GPIO_PA1_T0CCP1 ); //Set the pins as timer pins. GPIOPinTypeTimer(PA_FAN_TACHOMETER_PORT, PA1_TCU_FAN_1_TACHOMETER_PIN); //Initialize the timer so timer 0B counts the number of positive edges while timer 0A counts up. //When timer 0B reaches a preset value check the timer 0A value and get the number of pulses/time. TimerConfigure(TIMER0_BASE, ( TIMER_CFG_SPLIT_PAIR | TIMER_CFG_A_PERIODIC | TIMER_CFG_B_CAP_TIME )); //Set the timers so timerA counts to 0.1S, and timerB counts to 1000 positive edges. TimerLoadSet(TIMER0_BASE, TIMER_BOTH, ui32SysClock/10); TimerControlEvent(TIMER0_BASE, TIMER_B, TIMER_EVENT_POS_EDGE); //set the initial value of the counter to 0. TCUFan1TimerValue = 0; IntRegister(INT_TIMER0B, InterruptHandlerTimer0B); //Configure timerB interrupt to occur when the count is reached. TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT); IntEnable(INT_TIMER0A); TimerIntEnable(TIMER0_BASE, TIMER_CAPB_EVENT); IntEnable(INT_TIMER0B); // Enable the timers. TimerEnable(TIMER0_BASE, TIMER_A); TimerEnable(TIMER0_BASE, TIMER_B); }
Interrupt handlers for the timer:
//Timer0B interrupt handler that calculates the RPM of TCU Fan 1. void InterruptHandlerTimer0A( void ){ //Clear the interrupt. TimerIntClear(TIMER0_BASE, TIMER_TIMA_TIMEOUT); //read the fan rpm data. Laser.Miscellaneous.Monitor.TCUFan1RMP = TCUFan1TimerValue*300; TCUFan1TimerValue=0; //Reset the value in timer0B to 0 HWREG(TIMER0_BASE + TIMER_O_TBV) = 0; } //interrupt handler for timer0B. void InterruptHandlerTimer0B( void ){ TimerIntClear(TIMER0_BASE, TIMER_CAPB_EVENT); TCUFan1TimerValue++; }
I get 0 for the variable called TCUFan1RPM that is set in the Timer0A interrupt handler. The logic is increment the global variable TCUFan1TimerValue on the pos-edge of the signal and see how big this variable is every time timer0A runs out. I also tried to do it so that I would just sample the posedge 1000 times and on the timeout event, see the value of Timer0A to see how long it takes to get 1000 posedges but this method didn't work because Timer0B did not want to be in Capture mode and also timeout.
Any help would be appreciated, I would like to get the second logic working but if we can get the first version working I will be happy too.