杰理 AC692N系列 3路PWM设置方法

1、默认的TIMER对应的PWM输出的IO口

PWM0–TIMER0–PA1
PWM1–TIMER1–PA4
PWM2–TIMER2–PB3
PWM3–TIMER3–PB4
PWM不通过OUTPUTCHANNEL设置的时候,PWM从默认的IO口输出

2、由于TIMER0作系统时钟,所以最多可以输出3路PWM,而且3路PWM可以通过OUTPUTCHANNEL
输出到任意的IO口上,输出3路PWM参考程序,
void led_pwm_init(void)
{
set_timer1_pwm(500L, 10);
set_timer3_pwm(500L, 50);
set_timer2_pwm(500L, 90);
}
static void set_timer1_pwm(u32 fre, u8 duty)
{
SFR(JL_IOMAP->CON3, 20, 4, 3);//CHANNEL1,对应输出IO口的OUT:0,DIE:1
JL_TIMER1->CON = 0x0000;
JL_TIMER1->PRD = OSC_Hz / (4 * fre);
JL_TIMER1->PWM = (JL_TIMER1->PRD * duty) / 100;
JL_TIMER1->CON = (1 << 4) | (1 << 8) | (1 << 0) | (2 << 2);
JL_PORTA->PU |= BIT(12);
JL_PORTA->PD |= BIT(12);
JL_PORTA->DIR &= ~BIT(12);
JL_PORTA->OUT &= ~BIT(13);
JL_PORTA->DIE |= BIT(12);
}

static void set_timer3_pwm(u32 fre, u8 duty)
{
SFR(JL_IOMAP->CON1, 8, 4, 15);//CHANNEL0,对应输出IO口的OUT:0,DIE:0
JL_TIMER3->CON = 0x0000;
JL_TIMER3->PRD = OSC_Hz / (4 * fre);
JL_TIMER3->PWM = (JL_TIMER3->PRD * duty) / 100;
JL_TIMER3->CON = (1 << 4) | (1 << 8) | (1 << 0) | (2 << 2);
JL_PORTA->PU |= BIT(13);
JL_PORTA->PD |= BIT(13);
JL_PORTA->DIR &= ~BIT(13);
JL_PORTA->OUT &= ~BIT(13);
JL_PORTA->DIE &= ~BIT(13);
}
static void set_timer2_pwm(u32 fre, u8 duty)
{
SFR(JL_IOMAP->CON3, 24, 4,14);//CHANNEL2,对应输出IO口的OUT:1,DIE:0
JL_TIMER2->CON = 0x0000;
JL_TIMER2->PRD = OSC_Hz / (4 * fre);
JL_TIMER2->PWM = (JL_TIMER2->PRD * duty) / 100;
JL_TIMER2->CON = (1 << 4) | (1 << 8) | (1 << 0) | (2 << 2);
JL_PORTB->PU |= BIT(13);
JL_PORTB->PD |= BIT(13);
JL_PORTB->DIR &= ~BIT(13);
JL_PORTB->OUT|= BIT(13);
JL_PORTB->DIE &= ~BIT(13);
}

你可能感兴趣的:(杰理 AC692N系列 3路PWM设置方法)