<dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><s id="yhprb"><strike id="yhprb"></strike></s></dfn><small id="yhprb"></small><dfn id="yhprb"></dfn><small id="yhprb"><delect id="yhprb"></delect></small><small id="yhprb"></small><small id="yhprb"></small> <delect id="yhprb"><strike id="yhprb"></strike></delect><dfn id="yhprb"></dfn><dfn id="yhprb"></dfn><s id="yhprb"><noframes id="yhprb"><small id="yhprb"><dfn id="yhprb"></dfn></small><dfn id="yhprb"><delect id="yhprb"></delect></dfn><small id="yhprb"></small><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn> <small id="yhprb"></small><delect id="yhprb"><strike id="yhprb"></strike></delect><dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"><s id="yhprb"><strike id="yhprb"></strike></s></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn>

新聞中心

EEPW首頁(yè) > 嵌入式系統 > 設計應用 > STM32在定時(shí)器中控制步進(jìn)電機

STM32在定時(shí)器中控制步進(jìn)電機

作者: 時(shí)間:2016-11-21 來(lái)源:網(wǎng)絡(luò ) 收藏
寫(xiě)WEB程序的時(shí)候,發(fā)現如果加上步進(jìn)電機控制的話(huà),就會(huì )出現問(wèn)題。原因是如果把電機控制放在uip循環(huán)中處理的話(huà),因為控制電機涉及到時(shí)間問(wèn)題。所以必須解決,想到的方法就是多任務(wù)的思想。把步進(jìn)電機的處理放在定時(shí)器中斷里面。這樣的話(huà)就能避免問(wèn)題了。順便學(xué)習了庫函數操作定時(shí)器。這里用到的定時(shí)器功能簡(jiǎn)單,只需要產(chǎn)生更新中斷。

下面是定時(shí)器初始化代碼

本文引用地址:http://dyxdggzs.com/article/201611/319101.htm
  1. //定時(shí)器3初始化
  2. //arr:定時(shí)重裝值
  3. //psc:分頻值
  4. voidTIM3_Init(uint16_tarr,uint16_tpsc)
  5. {
  6. TIM_TimeBaseInitTypeDefTIM_TimeBaseStructure;
  7. NVIC_InitTypeDefNVIC_InitStructure;
  8. RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3,ENABLE);//開(kāi)啟TIM3時(shí)鐘
  9. //定時(shí)器3配置,重載值、分頻值、分頻系數、計數模
  10. TIM_TimeBaseStructure.TIM_Period=arr;
  11. TIM_TimeBaseStructure.TIM_Prescaler=psc;
  12. TIM_TimeBaseStructure.TIM_ClockDivision=TIM_CKD_DIV1;
  13. TIM_TimeBaseStructure.TIM_CounterMode=TIM_CounterMode_Up;
  14. TIM_TimeBaseInit(TIM3,&TIM_TimeBaseStructure);
  15. TIM_ITConfig(TIM3,TIM_IT_Update,ENABLE);//允許定時(shí)更新中斷
  16. //中斷配置
  17. NVIC_InitStructure.NVIC_IRQChannel=TIM3_IRQn;
  18. NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=0;
  19. NVIC_InitStructure.NVIC_IRQChannelSubPriority=3;
  20. NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE;
  21. NVIC_Init(&NVIC_InitStructure);
  22. TIM_Cmd(TIM3,ENABLE);//使能定時(shí)器3
  23. }


定時(shí)器中斷處理函數

  1. voidTIM3_IRQHandler(void)
  2. {
  3. staticuint8_ti;//相序計數器
  4. if(TIM_GetITStatus(TIM3,TIM_IT_Update)!=RESET)
  5. {
  6. TIM_ClearITPendingBit(TIM3,TIM_IT_Update);
  7. Motorcw(i);//電機正轉
  8. i++;
  9. if(i==4)
  10. i=0;
  11. }
  12. }


電機正傳代碼函數

  1. voidMotorcw(uint8_ti)
  2. {
  3. GPIO_Write(GPIOC,phasecw[i]);
  4. }


這樣的話(huà)就不能干擾到uip的正常事件處理了。



評論


技術(shù)專(zhuān)區

關(guān)閉
国产精品自在自线亚洲|国产精品无圣光一区二区|国产日产欧洲无码视频|久久久一本精品99久久K精品66|欧美人与动牲交片免费播放
<dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><s id="yhprb"><strike id="yhprb"></strike></s></dfn><small id="yhprb"></small><dfn id="yhprb"></dfn><small id="yhprb"><delect id="yhprb"></delect></small><small id="yhprb"></small><small id="yhprb"></small> <delect id="yhprb"><strike id="yhprb"></strike></delect><dfn id="yhprb"></dfn><dfn id="yhprb"></dfn><s id="yhprb"><noframes id="yhprb"><small id="yhprb"><dfn id="yhprb"></dfn></small><dfn id="yhprb"><delect id="yhprb"></delect></dfn><small id="yhprb"></small><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn> <small id="yhprb"></small><delect id="yhprb"><strike id="yhprb"></strike></delect><dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"><s id="yhprb"><strike id="yhprb"></strike></s></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn>