dsPIC33CK256MP508 PWM---1

平台:dsPIC33CK256MP508  参照官方curiosity 自制开发板

文档:image


例子:研究的事官方的这个例子

image

代码如下:

代码是在curiosity 开发板官方例程上进行添加的(例程中包含了旋钮,按键,LED的驱动),代码下进去就可以运行了。



/*PWM control register configuration*/
PCLKCONbits.MCLKSEL = 3;
PG1CONLbits.CLKSEL = 1;
PG1CONLbits.MODSEL = 0b000; /*Independent edge triggered mode */
PG1CONH = 0x0000;
/*PWM Generator outputs operate in Complementary mode*/
/*PWM Generator controls the PWM1H and PWM1L output pins*/
/*PWM1H & PWM1L output pins are active high*/
PG1IOCONH = 0x000C;
/*PWM uses PG1DC, PG1PER, PG1PHASE registers*/
/*PWM Generator does not broadcast UPDATE status bit state or EOC signal*/
/*Update the data registers at start of next PWM cycle (SOC) */
/*PWM Generator operates in Single Trigger mode*/
/*Start of cycle (SOC) = local EOC*/
/*Write to DATA REGISTERS*/
PG1PER = 5000; /*PWM frequency is 100kHz*/
PG1DC = 1250; /* 25% duty*/
PG1PHASE = 500; /*Phase offset in rising edge of PWM*/
PG1DTH = 100; /*Dead time on PWMH */
PG1DTL = 100; /*Dead time on PWML*/

PG1EVTLbits.UPDTRG = 0x01; // 对PG1DC寄存器进行写操作时自动将UPDREQ位置1

/*Enable PWM*/
PG1CONLbits.ON = 1; /*PWM module is enabled*/


将potentiometer值直接赋给PG1DC 就可以改变占空比了。


image

posted @ 2021-10-10 15:30  Rocky_Zou  阅读(600)  评论(0编辑  收藏  举报