首先用C809做一个开环的PWM控制器:
做法参考
配置过程如下:
void TAU0_ini(void)
{
TMMK00=1; /*enable TAU channel0 interrupt*/
TMMK01=1; /*enable TAU channel1 interrupt*/
TMIF00 = 0; /*clear TAU channel01 interrupt*/
TMIF01 = 0; /*clear TAU channel01 interrupt*/
TMPR000 = 1; /*Set INTTM01 as the lowest priority*/
TMPR100 = 1;
TMPR001 = 1; /*Set INTTM01 as the lowest priority*/
TMPR101 = 1;
TAU0EN = 1; /*Clock input supply*/
// TPS0 = 0x66; /*Clock frequency is fCLK(313kHz) for CK00 & CK01*///66
TPS0 = 0x00;
/*TAU0 channel00 set*/
TMR00H = 0x00; //00 /*0---CK00 is fMCK*/
TMR00L = 0x00; /*00*/
/*0----fMCK*/
/*0----master channel*/
/*000--select only software start*/
/*00---Sets 00 because these are not used*/
/*00*/
/*000--interval timer*/
/*0----Neither INTTM00 nor invert timer output*/
/*TAU0 channel01 set*/
TMR01H = 0x04; /*0---CK00 is fMCK*/
TMR01L = 0x08; /*00*/
/*0----fMCK*/
/*0----slave channel*/
/*100--selects INTTM00 of master channel*/
/*00---Sets 00 because these are not used*/
/*00*/
/*100--One-count mode*/
/*0----Neither INTTM00 nor invert timer output*/
TOM0 =0x02; /*channel0 is used as master channel output for channel1*/
/*channel1 slave channel output*/
}
其次写一个占空比控制函数。周期固定,采用宏定义。
#define period_motor 0x0FFF
void TAU00_TAU01_PWM_setting(uint16_t PWM_duty) /*set the value of TDR0 and TDR1 for motor1*/
{
uint16_t dead_area_time;
// dead_area_time = period_motor / 100 * 70; /*duty cycle is set as 70%*/
dead_area_time = period_motor / 1000 *PWM_duty; /*duty cyde sets as PWM_duty‰*/
TDR00H = (uint8_t)(period_motor >> 8);
TDR00L = (uint8_t)period_motor;
TDR01H = (uint8_t)(dead_area_time >> 8);
TDR01L = (uint8_t)dead_area_time;
}
设置中断:
__interrupt void Interrupt_INTTM00(void) /*Stepper motor commutation operation*/
{
P0 = 0x00;
}
__interrupt void Interrupt_INTTM01(void) /*Stepper motor commutation operation*/
{
P0 = 0x02;
}
完成开环PWM控制。
接下来提出一些我的困惑:C809没有RTO,是否有更加方便的办法输出PWM信号。欢迎各位高手指点