
<tr> <td width="50%" style="vertical-align:top;padding:10px 10px 10px 0;"> </td> <td width="50%" style="vertical-align:top;padding:10px;"> </td> </tr> <tr> <td width="50%" style="vertical-align:top;padding:10px 10px 10px 0;"> </td> <td width="50%" style="vertical-align:top;padding:10px;"> </td> </tr> <tr> <td width="50%" style="vertical-align:top;padding:10px 10px 10px 0;"> </td> <td width="50%" style="vertical-align:top;padding:10px;"> </td> </tr> <tr> <td width="50%" style="vertical-align:top;padding:10px 10px 10px 0;"> </td> <td width="50%" style="vertical-align:top;padding:10px;"> </td> </tr> <tr> <td width="50%" style="vertical-align:top;padding:10px 10px 10px 0;"> </td> <td width="50%" style="vertical-align:top;padding:10px;"> </td> </tr> <p> * MSP432E401Y<p> * Description:本函数实现定时和测速功能 <p> * 引脚:PD0->编码器输入信号<p> * <p> * Author: Robin.J<p>*/<p><br/><p>/* DriverLib Includes */<p>#include <ti/devices/msp432e4/driverlib/driverlib.h><p><br/><p>/* Standard Includes */<p>#include <common.h><p><br/><p>uint32_t count = 0;<p>//uint32_t count1 = 0;<p>//uint32_t count2 = 0;<p><br/><p>uint32_t CNT1 = 0;<p>uint32_t CNT2 = 0;<p>int speed = 0;<p>uint32_t time1 = 0;<p><br/><p>void TIMER2A_IRQHandler(void)<p>{<p> uint32_t getTimerInterrupt;<p><br/><p> count++;//脉冲计数,高电平触发<p>// count1 = MAP_TimerValueGet(TIMER2_BASE,TIMER_B);<p>// count2 = MAP_TimerLoadGet(TIMER2_BASE,TIMER_B); <p> /* Get timer interrupt status and clear the same */<p> getTimerInterrupt = MAP_TimerIntStatus(TIMER2_BASE, true);<p> MAP_TimerIntClear(TIMER2_BASE, getTimerInterrupt);<p>}<p><br/><p>void TIMER1A_IRQHandler(void)<p>{<p> uint32_t getTimerInterrupt;<p><br/><p>// CNT1 = count;<p>// CNT2 = CNT1;<p>// speed = ((CNT1 - CNT2)/506) * 6000;<p>// count = 0;<p><br/><p> time1++;//计时,每10ms增1<p> if(time1 == 10){ <p> CNT1 = count;<p> }if(time1 == 20){<p><br/><p> CNT2 = count;<p> //count1 = CNT2 - CNT1;<p> speed = (int)(((CNT2 - CNT1)/506.0) * 600);<p> //count = 0;<p> time1 = 0;<p> count = 0;<p> }<p><br/><p>// s_r = speed;<p>// pid_r = IncPIDCalc_r(s_r);<p>// pid_r *= 0.01;<p>// pwm_pidr += pid_r;<p>// if(pwm_pidr > 0.99){<p>// <p>// pwm_pidr = 0.99;<p>// <p>// }<p>// <p>// PWM_init(pwm_pidl,0.8); <p> /* Get timer interrupt status and clear the same */<p> getTimerInterrupt = MAP_TimerIntStatus(TIMER1_BASE, true);<p> MAP_TimerIntClear(TIMER1_BASE, getTimerInterrupt);<p><br/><p>}<p><br/><p><br/><p>void GPT_init(void)<p>{<p><br/><p> MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);<p><br/><p> while(!(SysCtlPeripheralReady(SYSCTL_PERIPH_GPIOA)))<p> {<p> }<p><br/><p> MAP_GPIOPinConfigure(GPIO_PA4_T2CCP0);<p> MAP_GPIOPinTypeTimer(GPIO_PORTA_BASE, GPIO_PIN_4);<p> MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER2);<p> while(!(SysCtlPeripheralReady(SYSCTL_PERIPH_TIMER2)))<p> {<p> }<p><br/><p> MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER1);<p> while(!(SysCtlPeripheralReady(SYSCTL_PERIPH_TIMER1)))<p> {<p> }<p><br/><p> MAP_TimerConfigure(TIMER2_BASE, TIMER_CFG_SPLIT_PAIR | TIMER_CFG_A_CAP_TIME_UP);<p> MAP_TimerIntEnable(TIMER2_BASE, TIMER_CAPA_EVENT);<p> MAP_TimerControlEvent(TIMER2_BASE, TIMER_A, TIMER_EVENT_POS_EDGE);<p><br/><p><br/><p> MAP_TimerConfigure(TIMER1_BASE, TIMER_CFG_SPLIT_PAIR | TIMER_CFG_A_PERIODIC);<p> MAP_TimerIntEnable(TIMER1_BASE, TIMER_TIMA_TIMEOUT);<p><br/><p> /* Since the 16-bit timer can count only 65536 value, we use the pre<p> * scaler of 256 to divide down the count rate by 256. Thus the actual<p> * count load is16e6/256 = 62500. Now when to count at 0.1 sec the<p> * load value in the timer would be 62500 * 0.1 =6250. */<p> MAP_TimerPrescaleSet(TIMER1_BASE, TIMER_A, 255);<p> MAP_TimerLoadSet(TIMER1_BASE, TIMER_A, 625);//10ms<p> /* Enable Timer Interrupt */<p> MAP_IntEnable(INT_TIMER2A);<p><br/><p> MAP_IntEnable(INT_TIMER1A);<p><br/><p> /* Enable the timer count */<p> MAP_TimerEnable(TIMER2_BASE, TIMER_A);<p><br/><p> MAP_TimerEnable(TIMER1_BASE, TIMER_A);<p><br/><p><br/><p>}<p>/* (C) COPYRIGHT 2018 DY EleTe *END OF FILE/<p><br/>
讯享网

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容,请联系我们,一经查实,本站将立刻删除。
如需转载请保留出处:https://51itzy.com/kjqy/205329.html