完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
嗨,各位,也许这在某处是一个简单的省略,但是我不能从dspic33fj128mc802的PWM1H1端口得到任何pwm信号。预期的输出应该是在RB14的TrISB语句,如你在下面的代码中看到的。我试着在没有PPS的情况下产生这个信号,但是没有运气!我会感激任何输入。注意。//PWM具有由电机控制单元include
以上来自于百度翻译 以下为原文 Hi guys, Probably this is a simple omission somewhere, but I cannot get any pwm signal from PWM1H1 port of the dspic33fj128mc802. The expected output is supposed to be at RB14 by TRISB-statement as you see in the code below. I tried to produce this signal with and without PPS, but no luck! I would appreciate any input. Take care. // PWM has a single HIGH output generated by motor control unit #include // Configuration Register - FOSC #pragma config FCKSM = 3 // both clock switching and fail-safe modes are disabled #pragma config OSCIOFNC = 0 // OSCO pin is a general purpose I/O pin #pragma config POSCMD = 3 // primary oscillators are disabled // Configuration Register - FOSCSEL #pragma config IESO = 0 // start with a user-selected oscillator at reset #pragma config FNOSC = 7 // select FRC oscillator with postscalar at reset // Configuration Register - Motor Control PWM FPOR #pragma config PWMPIN = 0 // All Motor Control PWM outputs are active at Reset #pragma config HPOL = 1 // Motor control HIGH outputs are active high #pragma config LPOL = 1 // Motor control LOW outputs are active high //#define PPSUnLock __builtin_write_OSCCONL(OSCCON & 0xBF) //#define PPSLock __builtin_write_OSCCONL(OSCCON | 0x40) int main () { // OSCTUN Register OSCTUNbits.TUN = 0; // select FRC = 7.37MHz // CLKDIV Register CLKDIVbits.ROI = 0; // interrrupts have no effect on clock recovery CLKDIVbits.FRCDIV = 6; // FRCDIVN = FRC/64 = 7.37/64 = 115.15KHz -> FOSC CLKDIVbits.DOZE = 1; // FOSC/4 = 115.15/4 = 28.8KHz -> FCY CLKDIVbits.DOZEN = 1; // DOZE defines the ratio between cpu and peripheral clocks // Define RB14 as an output for PWM1H1 TRISBbits.TRISB14 = 0; // Pin RB14 is assigned as output // PWM1 timebase control register P1TCONbits.PTEN = 0; // Do not enable the clock delivery to PWM1 timer yet P1TCONbits.PTCKPS = 0; // Prescale is 1:1 so Timer2 clock = 28.8KHz P1TCONbits.PTMOD = 0; // PWM1 is in free-running mode // PWM1 counter and period P1TMRbits.PTMR = 0; // Initial value in PWM1 counter register P1TPER = 576; // PWM1 period register -> PWM period // PWM1 control register1 PWM1CON1bits.PMOD3 = 1; // PWM1H3 and PWM1L3 outputs are independent mode PWM1CON1bits.PMOD2 = 1; // PWM1H2 and PWM1L2 outputs are independent mode PWM1CON1bits.PMOD1 = 1; // PWM1H1 and PWM1L1 outputs are independent mode PWM1CON1bits.PEN3H = 0; // PWM1H3 is disabled PWM1CON1bits.PEN2H = 0; // PWM1H2 is disabled PWM1CON1bits.PEN1H = 1; // PWM1H1 is enabled PWM1CON1bits.PEN3L = 0; // PWM1H3 is disabled PWM1CON1bits.PEN2L = 0; // PWM1H2 is disabled PWM1CON1bits.PEN1L = 0; // PWM1H1 is disabled // PWM1 control register2 PWM1CON2bits.IUE = 0; // Updates are synchronized with timebase PWM1CON2bits.UDIS = 0; // Updates from period and duty cycle registers are enabled // PWM1 duty cycle register1 P1DC1 = 29; // Duty cycle register1 will produce 1msec pulse //PPSUnLock; // Use RP14 for PWM1H1 //RPOR7bits.RP14R = 0; //Redirect PWM1H1 to RP14 //PPSLock; // Enable timebase control register P1TCONbits.PTEN = 1; // Enable the clock delivery to PWM1 timer while (1); } |
|
相关推荐
2个回答
|
|
我前面没有这个芯片的数据表,但是我已经设置了几种不同配置的PWM输出。需要查找的是:提供时基的是什么(有时是定时器,并且定时器需要运行)。pwm时基定时器是否实际运行(启用定时器中断并在其中粘贴断点)pwm模块是否实际运行(启用pwm中断并在其中粘贴断点)最后,如果所有这些工作正常,检查IOCONx寄存器(如果您的芯片上有这些寄存器),以确保pwm输出与引脚绑定。
以上来自于百度翻译 以下为原文 I don't have a datasheet for that chip in front of me, but I've set a few PWM outputs up in various configurations. Some things to look for:
|
|
|
|
事实上,这是一个MPLABX问题。它没有正确运行。我创建了一个相同的项目,然后它运行没有任何黑客。谢谢你的帮助。
以上来自于百度翻译 以下为原文 Actually, it was an mplabx problem. It was not running correctly. I created an identical project, and then it ran without any hick up. Thank you for the help. |
|
|
|
只有小组成员才能发言,加入小组>>
5243 浏览 9 评论
2035 浏览 8 评论
1955 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3208 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2258 浏览 5 评论
779浏览 1评论
672浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
598浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
680浏览 0评论
578浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-24 18:19 , Processed in 1.578120 second(s), Total 79, Slave 63 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号