“线程”中讨论的其它部件:EK-TM4C1294XL
大家好,我有一个定制板,可以控制一些风扇并记录它们的 RPM。 风扇通过 PWM 信号进行控制,风扇有一个转速表,该转速表连接到主板上的多个 CCP 针脚。 我将使用连接到 T0CCP1的风扇1来解决此问题,因为所有其它 风扇都应该相同,并为其配置不同的针脚。 这是我目前为止拥有的代码和电路。
与转速表的针脚连接:
风扇转速表输出信息。
设置计时器的代码:
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); }
计时器的中断处理程序:
//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++; }
对于在 Timer0A 中断处理程序中设置的名为 TCUFan1RPM 的变量,我获得0。 逻辑是在 信号的位置边缘增加全局变量 TCUFan1TimerValue,并查看每次 timer0A 用完时该变量的大小。 我还尝试这样做,这样我就可以对 POSedge 进行1000次采样,并在超时事件上进行采样, 查看 Timer0A 的值以了解获取1000个位置所需的时间,但此方法不起作用,因为 Timer0B 不想处于“捕获”模式,也不想处于超时状态。
如果有任何帮助,我希望第二个逻辑能够正常工作,但如果我们能使第一个版本正常工作,我也会很高兴。