完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
我使用代码配置器在这个PIC上设置PWM,但是似乎不能得到输出。我用MICROStiCK2作为我的基础。下面是我的振荡器和PWM初始化的代码。我看了很难,但找不到任何错误的代码。有什么想法,为什么不工作?谢谢
以上来自于百度翻译 以下为原文 I am using Code Configurator to set up PWM on this PIC but can't seem to get an output. I am using Microstick2 as my base. Below is the code for my Oscillator and PWM initialization. I have looked hard but cannot find anything wrong in the code. Any thoughts why this isn't working? Thanks void OSCILLATOR_Initialize(void) { // CF no clock failure; NOSC FRCPLL; CLKLOCK unlocked; OSWEN Switch is Complete; __builtin_write_OSCCONL((uint8_t) (0x100 & 0x00FF)); // FRCDIV FRC/1; PLLPRE 2; DOZE 1:8; PLLPOST 1:2; DOZEN disabled; ROI disabled; CLKDIV = 0x3000; // TUN Center frequency; OSCTUN = 0x0; // ROON disabled; ROSEL disabled; RODIV Base clock value; ROSSLP disabled; REFOCON = 0x0; // PLLDIV 64; PLLFBD = 0x40; // RND disabled; SATB disabled; SATA disabled; ACCSAT disabled; CORCONbits.RND = 0; CORCONbits.SATB = 0; CORCONbits.SATA = 0; CORCONbits.ACCSAT = 0; } void PWM_Initialize (void) { // PCLKDIV 1; PTCON2 = 0x0; // PTPER 1023; PTPER = 0x3FF; // SEVTCMP 0; SEVTCMP = 0x0; // MDC 0; MDC = 0x0; // CHOPCLK 0; CHPCLKEN disabled; CHOP = 0x0; // PWMKEY 0; PWMKEY = 0x0; // MDCS Primary; FLTIEN disabled; CAM Edge Aligned; DTC Dead-time function is disabled; TRGIEN disabled; XPRES disabled; ITB Master; IUE disabled; CLIEN disabled; MTBS disabled; DTCP disabled; PWMCON1 = 0x80; // MDCS Primary; FLTIEN disabled; CAM Edge Aligned; DTC Positive dead time; TRGIEN disabled; XPRES disabled; ITB Master; IUE disabled; CLIEN disabled; MTBS disabled; DTCP disabled; PWMCON2 = 0x0; // MDCS Primary; FLTIEN disabled; CAM Edge Aligned; DTC Positive dead time; TRGIEN disabled; XPRES disabled; ITB Master; IUE disabled; CLIEN disabled; MTBS disabled; DTCP disabled; PWMCON3 = 0x0; //FLTDAT PWM1L Low, PWM1H Low; SWAP disabled; OVRENH disabled; PENL enabled; PMOD Redundant Output Mode; OVRENL disabled; OSYNC disabled; POLL disabled; PENH enabled; CLDAT PWM1L Low, PWM1H Low; OVRDAT PWM1L Low, PWM1H Low; POLH disabled; __builtin_write_PWMSFR(&IOCON1, 0xC400, &PWMKEY); //FLTDAT PWM2L Low, PWM2H Low; SWAP disabled; OVRENH disabled; PENL disabled; PMOD Complementary Output Mode; OVRENL disabled; OSYNC disabled; POLL disabled; PENH disabled; CLDAT PWM2L Low, PWM2H Low; OVRDAT PWM2L Low, PWM2H Low; POLH disabled; __builtin_write_PWMSFR(&IOCON2, 0x0, &PWMKEY); //FLTDAT PWM3L Low, PWM3H Low; SWAP disabled; OVRENH disabled; PENL disabled; PMOD Complementary Output Mode; OVRENL disabled; OSYNC disabled; POLL disabled; PENH disabled; CLDAT PWM3L Low, PWM3H Low; OVRDAT PWM3L Low, PWM3H Low; POLH disabled; __builtin_write_PWMSFR(&IOCON3, 0x0, &PWMKEY); //FLTPOL disabled; CLPOL disabled; CLSRC FLT1; CLMOD disabled; FLTMOD Fault input is disabled; FLTSRC FLT32; __builtin_write_PWMSFR(&FCLCON1, 0xFB, &PWMKEY); //FLTPOL disabled; CLPOL disabled; CLSRC FLT1; CLMOD disabled; FLTMOD PWM2H, PWM2L pins to FLTDAT values- Latched; FLTSRC FLT32; __builtin_write_PWMSFR(&FCLCON2, 0xF8, &PWMKEY); //FLTPOL disabled; CLPOL disabled; CLSRC FLT1; CLMOD disabled; FLTMOD PWM3H, PWM3L pins to FLTDAT values- Latched; FLTSRC FLT32; __builtin_write_PWMSFR(&FCLCON3, 0xF8, &PWMKEY); // PDC1 511; PDC1 = 0x1FF; // PDC2 0; PDC2 = 0x0; // PDC3 0; PDC3 = 0x0; // PHASE1 0; PHASE1 = 0x0; // PHASE2 0; PHASE2 = 0x0; // PHASE3 0; PHASE3 = 0x0; // DTR1 0; DTR1 = 0x0; // DTR2 0; DTR2 = 0x0; // DTR3 0; DTR3 = 0x0; // ALTDTR1 0; ALTDTR1 = 0x0; // ALTDTR2 0; ALTDTR2 = 0x0; // ALTDTR3 0; ALTDTR3 = 0x0; // TRGCMP 0; TRIG1 = 0x0; // TRGCMP 0; TRIG2 = 0x0; // TRGCMP 0; TRIG3 = 0x0; // TRGDIV 1; TRGSTRT 0; TRGCON1 = 0x0; // TRGDIV 1; TRGSTRT 0; TRGCON2 = 0x0; // TRGDIV 1; TRGSTRT 0; TRGCON3 = 0x0; // BPLL disabled; BPHH disabled; BPLH disabled; BCH disabled; FLTLEBEN disabled; PLR disabled; CLLEBEN disabled; BCL disabled; PLF disabled; PHR disabled; BPHL disabled; PHF disabled; LEBCON1 = 0x0; // BPLL disabled; BPHH disabled; BPLH disabled; BCH disabled; FLTLEBEN disabled; PLR disabled; CLLEBEN disabled; BCL disabled; PLF disabled; PHR disabled; BPHL disabled; PHF disabled; LEBCON2 = 0x0; // BPLL disabled; BPHH disabled; BPLH disabled; BCH disabled; FLTLEBEN disabled; PLR disabled; CLLEBEN disabled; BCL disabled; PLF disabled; PHR disabled; BPHL disabled; PHF disabled; LEBCON3 = 0x0; // LEB 0; LEBDLY1 = 0x0; // LEB 0; LEBDLY2 = 0x0; // LEB 0; LEBDLY3 = 0x0; // CHOPLEN disabled; CHOPHEN disabled; BLANKSEL No state blanking; CHOPSEL No state blanking; AUXCON1 = 0x0; // CHOPLEN disabled; CHOPHEN disabled; BLANKSEL No state blanking; CHOPSEL No state blanking; AUXCON2 = 0x0; // CHOPLEN disabled; CHOPHEN disabled; BLANKSEL No state blanking; CHOPSEL No state blanking; AUXCON3 = 0x0; // SYNCOEN disabled; SEIEN disabled; SESTAT disabled; SEVTPS 1; SYNCSRC SYNCI1; SYNCEN disabled; PTSIDL disabled; PTEN enabled; EIPU disabled; SYNCPOL disabled; PTCON = 0x8000; } |
|
相关推荐
2个回答
|
|
事实证明,这个代码确实有效,但并不稳定。如果我只把代码下载到MICROSTICK2,即使看到一个好的固态振荡器信号,也不会得到PWM输出。我使用的是内部FRC振荡器。但是,如果我触摸板上的一些引脚,PWM开始?这似乎不重要,我是否降低了振荡器频率通过减少PLL反馈,我得到相同的结果。这是我应该在MICROSTICK论坛中问的问题,还是与DSIC33有关的问题。谢谢你的建议。
以上来自于百度翻译 以下为原文 It turned out that this code does work but isn't stable. If I just download the code to the Microstick2 I get no PWM output even though I see a good solid oscillator signal. I am using the internal FRC oscillator. If however I touch some pins on the board the PWM starts?? It doesn't seem to matter whether I lower the oscillator frequency by reducing the PLL feedback I get the same result. Is this a question I should be asking in the Microstick forum or is it something to do with the dsPIC33. Thanks for any advice on this. |
|
|
|
事实证明,浮动输入是罪魁祸首,如果路上有人读到这一点,也会得到同样的结果。
以上来自于百度翻译 以下为原文 It turned out that floating inputs were the culprit in case anyone down the road read this and are getting the same results. |
|
|
|
只有小组成员才能发言,加入小组>>
5231 浏览 9 评论
2026 浏览 8 评论
1950 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3200 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2253 浏览 5 评论
771浏览 1评论
659浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
588浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
669浏览 0评论
571浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-19 10:51 , Processed in 1.286790 second(s), Total 84, Slave 66 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号