大家有没有做过TM00定时器作为PWM输出啊?这个真是头痛死我了、、、
大家有没有做过TM00定时器作为PWM输出啊?这个真是头痛死我了、、、下面的代码是生成的。我在程序里利用第三个函数 更改占空比后 有时候会乱掉、、、、
void TM00_Init(void)
{
CRC00 = 0x00;
CR000 = TM00_CR000_VALUE;
CR010 = TM00_CR010_VALUE;
PRM00 = TM0_INTER_CLOCK_2;
TOC00 = 0x1b;
TMC00 = 0x0c;
// TOC00 = TM0_SUCCESSIVE_MODE | TM0_SOFTWARE_TRIGGER_OFF | TM0_CR00_OUTPUT_FF_ON_MODE | TM0_CR01_OUTPUT_FF_ON_MODE | TM0_OUTPUT_ENABLE_BIT;
/* Set TO00 pin */
PM3 &= 0xFD;
P3 &= 0xFD;
}
void TM00_Start(void)
{
TMIF000 = 0; /* clear INTTM000 flag */
TMMK000 = 0; /* enable INTTM000 */
TMIF010 = 0; /* clear INTTM010 flag */
TMMK010 = 0; /* enable INTTM010 */
TOE00 = 1; /* enable output */
TOC00 |= TM0_OUTPUT_INIT_LEVEL_LOW;
TMC00 &= (UCHAR)~TM0_OPERATE;
TMC00 |= TM0_CLEAR_BY_MATCH_CR00;
}
void TM00_ChangeDuty(UCHAR ratio)
{
ULONG cycle = CR000 + 1;
ULONG reg = 0;
if (ratio > 100)
{
ratio = 100;
}
reg = cycle * ratio / 100 - 1;
TMMK000 = 1; /* disable INTTM000 */
TOC00 &= 0xfe;
CR010 = (USHORT)reg;
NOP();
NOP();
TOC00 |= 0x01;
TMMK000 = 1;
}
页:
[1]