void Init_TIM2(void)
{
//计数器禁止、ARR预装载禁止、向上计数、边沿对齐模式
TIM2->CR1 = BIT2;
//禁止TIM2所有中断
TIM2->IER = 0;//禁止中断
TIM2->CCMR1 = 0x01;//TIM2的CH1CH2CH3通道配置为输入
TIM2->CCMR2 = 0x01;
TIM2->CCMR3 = 0x01;
#define IC_FILTER (u8)(5 << 4)
TIM2->CCMR1 |= IC_FILTER; //输入捕获滤波器
TIM2->CCMR2 |= IC_FILTER;
TIM2->CCMR3 |= IC_FILTER;
//prescale = div3
@ 16MHz -> 0.5us/count * 24MHz -> 0.33us/count
TIM2->PSCR = 0;
TIM2->ARRH=0xff;//计数周期设为最大
TIM2->ARRL=0xff;
TIM2->CCER1 |= 0x01;//TIM2的CH1CH2CH3通道使能捕获功能
TIM2->CCER1 |= 0x10;
TIM2->CCER2 |= 0x01;
TIM2->CR1 |= 0x01;//使能TIM2定时器
}
此帖出自
小平头技术问答
#include "hall.h"
unsigned char bHallStartStep;//换相步序变量定义
//换相步序值0-5分别对应ABACBCBACACB
unsigned int OutPwmValue=0;//PWM输出值变量定义
unsigned char St_F=0;//启停标志,0时为停止,1时为启动
unsigned char FaultF=0;//故障标志
unsigned char Run_dir=0;//运转方向,0-1对立
unsigned char bHallSteps[2][8]={
{7,5,3,4,1,0,2,7},//正转
{7,2,0,1,4,3,5,7}//反转
};
const unsigned char PWM_EN1_TAB[6]={0x01,0x01,0x10,0x10,0x00,0x00};
//六步法中,CH1CH2通道极性及使能配置
const unsigned char PWM_EN2_TAB[6]={0x0,0x00,0x00,0x0,0x1,0x1};
//六步法中,CH3通道极性及使能配置
最后这两行啥意思
对应什么寄存器 这六个地址啥意思
一周热门 更多>