完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
我想USPIC33 FJ16GS502没有外部振荡器来生成补充PWM。这是我的代码。我不知道为什么我的代码不能工作。我不能看到任何PWM输出的示波器。请帮助。
以上来自于百度翻译 以下为原文 I want to use pic33FJ16GS502 without external oscillator to generate Complementary PWM. Here is my code. I cannot figure out why my code does not work. I cannot observe any PWM output by the oscilloscope. Please Help. #include #include #include _FOSCSEL(FNOSC_FRCPLL) //set clock for internal OSC with PLL _FOSC(OSCIOFNC_OFF & POSCMD_NONE) //no clock output, external OSC disabled _FWDT(FWDTEN_OFF) //disable the watchdog timer _FICD(JTAGEN_OFF & ICS_PGD2) //disable JTAG, enable debugging on PGx1 pins void init_PWM(void); int main() { ACLKCONbits.FRCSEL = 1; // FRC provides input for Auxiliary PLL (x16) ACLKCONbits.SELACLK = 1; // Auxiliary Oscillator provides clock source for PWM & ADC ACLKCONbits.APSTSCLR = 7; // Divide Auxiliary clock by 1 ACLKCONbits.ENAPLL = 1; // Enable Auxiliary PLL while(ACLKCONbits.APLLCK != 1); // Wait for Auxiliary PLL to Lock init_PWM(); while(1); // Infinite Loop } void init_PWM() { IOCON1bits.PENH = 1; // PWM1H is controlled by PWM module IOCON1bits.PENL = 1; // PWM1L is controlled by PWM module IOCON1bits.PMOD = 0; // Select Complementary Output PWM mode IOCON1bits.POLH = 0; // PWMxH is active-high IOCON1bits.POLL = 0; // PWMxL is active-high IOCON1bits.OVRENH = 0; // PWMxH override disabled IOCON1bits.OVRENL = 0; // PWMxL override disabled IOCON1bits.FLTDAT = 0; // State for PWMxH PWMxL if FLTMOD enabled IOCON1bits.CLDAT = 0; // State for PWMxH PWMxL if CLMOD enabled IOCON1bits.SWAP = 0; // Don't swap PWMxH and PWMxL pins IOCON1bits.OSYNC = 0; // Overrides via OVRDAT occur on the next CPU clock PWMCON1bits.FLTIEN = 0; // Disable fault interrupts PWMCON1bits.CLIEN = 0; // Disable current limit interrupts PWMCON1bits.TRGIEN = 0; // Disable trigger interrupts PWMCON1bits.ITB = 0; // PTPER provides the PWM time period value PWMCON1bits.MDCS = 0; // PDCX/SDCX provides duty cycle value PWMCON1bits.DTC = 0; // Positive Dead Time applied for all modes PWMCON1bits.CAM = 0; // Edge aligned mode. PWMCON1bits.XPRES = 0; // External PWM reset disabled PWMCON1bits.IUE = 0; // Updates to MDC/PDC/SDC are synced to PWM time base PTCONbits.PTEN = 1; // Enable the PWM Module FCLCON1bits.FLTMOD = 3; // Fault input is disabled TRISAbits.TRISA4 = 0; LATAbits.LATA4 = 1; PTPER = 9426; PDC1 = 4717; // Independent Primary Duty Cycle is 5 ?s from Equation DTR1 = 95; // Deadtime = (65ns / 1.04ns) where 65ns is desired deadtime ALTDTR1 = 95; // ALTDeadtime = (65ns / 1.04ns) where 65ns is desired deadtime PHASE1 = 0; // No phase shift SPHASE1= 0; // No phase shift } |
|
相关推荐
10个回答
|
|
你好,Jackoyau,有一个关于FLCON的误读需要整个字,而不是一点点。另外,我认为它应该在模块关闭时写入,而您的模块使能就在您编写它之前。我只看了一下你的代码,和我的相比,到目前为止!祝你好运。
以上来自于百度翻译 以下为原文 Hello Jackoyau, There was an erratum about flcon needing to be written as a whole word, rather than bit wise. Also, I think it should be written to while the module is off, and your module enable comes just before you write to it. I have only glanced at your code and compared with mine so far! Good luck. |
|
|
|
我不理解“全字写作”的含义。
以上来自于百度翻译 以下为原文 I do not understand the meaning of "written as whole word" |
|
|
|
我找不到PWM与一些时钟/计时器的关联。是我错了还是你错过了这一部分?(没有一些时钟PWM不能运行)。术语“某些时钟”不适用于仅仅有一些系统时钟:必须有一个明确的时钟源的PWM模块。
以上来自于百度翻译 以下为原文 I could not find an association of the PWM with some clock/timer. Am I wrong or did you miss this part? (Without some clock PWM cannot run. And the term "some clock" does not apply on merely having some system clock: there has to be a well-defined clock source for the PWM module.) |
|
|
|
如果我没有任何外部时钟源,我怎么能只用DSPIC生成PWM呢?我的意思是如何正确设置时钟。
以上来自于百度翻译 以下为原文 If I do not have any external clock source, how can I generate PWM by the dspic only? I mean how to set the clock correctly. |
|
|
|
不需要一个“外部”时钟-任何时钟都可以。但是你必须定义PWM将基于哪个时钟。为什么不开始阅读数据表中相应的章节加上相应的FRM?(或者用样本代码查找一些应用笔记?)但我认为它应该瞄准你的衍生品。将此移植到另一个衍生物可能目前超出了你的能力。
以上来自于百度翻译 以下为原文 No need for an "external" clock - any clock will do. But you have to define which clock the PWM will be based upon. Why not start reading the corresponding chapter in your datasheet plus the corresponding FRM ? (Or look for some application note with sample code? But I assume it should be targeting YOUR derivative. Porting this to another derivative might currently be beyond your capabilities.) |
|
|
|
我已经阅读了几篇参考文献和数据表,这些天我尝试了不同的代码。但是,它仍然不起作用。我不能确定它是否是设置振荡器的问题,或者别的什么。例如,我把它添加到我的代码中,但是仍然没有输出。
以上来自于百度翻译 以下为原文 I have read several of references and the datasheet. And I tried different codes in these days. But still, it does not work. I cannot figure out if it is the problem of setting the oscillator, or anything else. For instance, I have added this into my code, but still no output. /* Configure Oscillator to operate the device at 40Mhz Fosc= Fin*M/(N1*N2), Fcy=Fosc/2 Fosc= 7.37*(43)/(2*2)=80Mhz for Fosc, Fcy = 40Mhz */ /* Configure PLL prescaler, PLL postscaler, PLL divisor */ PLLFBD=41; /* M = PLLFBD + 2 */ CLKDIVbits.PLLPOST=0; /* N1 = 2 */ CLKDIVbits.PLLPRE=0; /* N2 = 2 */ __builtin_write_OSCCONH(0x01); /* New Oscillator FRC w/ PLL */ __builtin_write_OSCCONL(0x01); /* Enable Switch */ while(OSCCONbits.COSC != 0b001); /* Wait for new Oscillator to become FRC w/ PLL */ while(OSCCONbits.LOCK != 1); /* Wait for Pll to Lock */ |
|
|
|
如果你对振荡器有疑问,从切换一些引脚开始——连接一个或多个LED来指示主时钟设置正确。(在这一点上,你可以使用延迟宏来把触发频率降到2赫兹。)一旦你掌握了这一步,你可以继续尝试使PWM上升和运行。…
以上来自于百度翻译 以下为原文 If you're in doubt with the oscillator, start with toggling some pin(s) - attaching one or more LED(s) to indicate you've got the main clock setup right. (At this point you may use the delay macros to get the toggle frequency down to e.g. 2 Hz.) Once you mastered this step, you may proceed with trying to get the PWM up and running. One step after the other . . . |
|
|
|
到OP:我终于可以把你的代码粘贴到我的GS502的测试项目中了。(100 kHz PWM在PWM1H上占空比50%,对吗?)我的意思是,有很多事情我可能会做得不同,但我只是想让你(和其他助手)知道它对我的工作方式,你告诉我们。所以,我的问题是:你的开发平台是什么?我问的原因是我已经从PIC10评估了几十个PIC设备,包括PIC32。对于DIP封装中的设备,我通常使用一些“预布线”SBBs(Solderless Breadboards),我一直在手上。只需几分钟就可以连接到串口、电源、PICTIT3。但是这里的事情……对于DSPIC33 EP设备来说,SBS通常会在25 MIPS之上。试验更多、更重、更高质量的旁路盖和VCAP有时有帮助,但通常不太多。(我可以以更高的时钟速度运行PIC32,没有问题。这只是DSPIC33 EPS,更为易怒。)对于像GS502这样的设备,接通APLL会在更低的工作频率下产生问题。因此,对于这个测试,我使用的是一个手动的电路板。(两个接地平面,每孔镀一个焊盘)。优质的DIP-28插座。从9V墙疣供应板3.3V调节器。花园品种100 NF绕道和10 UF MLCC VCAP。也许你可以加强你的VCAP和旁路电容器。(就像感冒的鸡汤:不会伤害;可能会帮助。)也会想到……因为PWM输出的方式不取决于系统频率,也许测试可以慢下来使用FRC(没有PLL),看看它是否有帮助。同样,为了测试的目的,尝试驱动直接从FRC(没有APLL)PWM,看看是否有帮助。我使测试程序输出自我记录尽可能多的实际。这是我的显示你的配置设置,振荡器设置,和PWM设置,在我的有线电路板:由DaveW7X在2月7日2018在18:4:52 PST与XC16版本1033 CPU是DSPIC33 FJ16GS502配置为FrcCl PLLFCY=39613750赫兹(39.61375 MIPS)CKDIVITUSS.PLLPREY=0,PLLFBD=41,CLKDIVbits.PLLPOST=0PWM,由FRCFRC驱动的APLL=7370000 Hz,PWM频率=100000 Hz,占空比=1/2PWM寄存器:PTP= 9426,PDC1= 417毫秒计数器周期寄存器PR1=36613问候,戴夫
以上来自于百度翻译 以下为原文 To the OP: I have finally gotten around to pasting your code into a test project for my 'GS502. It works as I think you intended. (100 kHz PWM on PWM1H with 50% duty cycle ratio, right?) I mean, there are are a number of things I might do differently, but I just wanted to let you (and the other helpers) know that it works for me the way you have shown us. So, my question is: What is your development platform? The reason I ask is that I have evaluated dozens of PIC devices from PIC10 up to and including PIC32. For devices in DIP packages I usually use one of a number of "pre-wired" SBBs (Solderless Breadboards) that I keep on hand. Only takes a couple of minutes to hook up to serial port, power, PICkit3. But here's the thing... For dsPIC33EP devices the SBBs typically crap out above something like 25 MIPS. Experimenting with more and heavier and higher quality bypass caps and Vcap sometimes helps, but usually not very much. (I can run PIC32s at much higher clock speeds with no problems. It's just the dsPIC33EPs that are more persnickety.) Also... For devices like the 'GS502, turning on the APLL makes problems at even lower operating frequencies. So... For this test I am using a hand-wired breadboard. (Ground planes on both sides, plated-through pad-per-hole. Good quality DIP-28 Socket. On-board 3.3V regulator from 9V wall-wart supply. Garden-variety 100 nF bypasses and 10 uF MLCC Vcap. Perhaps you can beef up your Vcap and bypass capacitors. (Like chicken soup for a cold: can't hurt; might help.) Also, it comes to mind... Since the PWM output for the way you configured it doesn't depend on system frequency, maybe for testing you could slow it down to just use FRC (no PLL) and see if it helps. Similarly, for test purposes try to drive the PWM directly from FRC (no APLL) and see if that helps. I make test program outputs self-documenting as much as practical. Here's what mine shows me with your configuration settings, oscillator settings, and PWM settings, on my wired breadboard: Compiled by davekw7x on Feb 7 2018 at 18:42:53 PST with XC16 version 1033 CPU is dsPIC33FJ16GS502 configured for FRC_PLL FCY = 39613750 Hz (39.61375 MIPS) CLKDIVbits.PLLPRE = 0, PLLFBD = 41, CLKDIVbits.PLLPOST = 0 PWM operating with APLL driven by FRC FRC = 7370000 Hz, PWM Frequency = 100000 Hz, duty cycle ratio = 1/2 PWM Registers: PTPER = 9426, PDC1 = 4717 Millisecond counter period register PR1 = 39613 Regards, Dave |
|
|
|
谢谢您的详细答复=)它应该是有用的。我会设法解决这个问题的。(硬件/软件)
以上来自于百度翻译 以下为原文 Thank you for your detail reply =) It should be useful. I will try to figure out the problem. (hardware /software ) |
|
|
|
我讨厌重复自己的问题,但是你发布的问题(没有PWM输出)不在你发布的软件中。我创建了一个全新的项目,使用了你第一个帖子的源代码。我把你的代码中的所有东西都保持不变,我没有添加任何东西。结果:100 kHz的互补PWM输出WI。第50%个占空比在PWM1H和PWM1L PSN.XC8版本1.33(自由模式)。我警告过您指定配置位的方式的不可取性,但我没有将它们更改为现在首选的规范。这个想法是,不管软件可能存在的问题和我(或其他助手)可能提供的建议,您的软件确实给出了我所指示的输出。时期。底线:有两件事我会改变我自己的项目,但事实是,你必须调查你的硬件。我问过你们的开发设置。如果它是一个PC板,请给我们一个示意图并告诉我们是否有接地平面,并告诉我们VCCAP和旁路电容器所用的部件。如果它是一个电路板,请描述电源/接地,并告诉我们绕过和VCAP组件。
以上来自于百度翻译 以下为原文
Result: 100 kHz complementary PWM output with 50% duty cycle on the PWM1H and PWM1L pins. XC8 version 1.33 (Free mode). I got warnings about the deprecatedness of the way you specified the configuration bits, but I didn't change them to the now-preferred specifications. The idea is that, regardless of software "issues" that might exist and recommendations that I (or other helpers) might offer, your software did give the outputs that I indicated. Period. Full Stop. Bottom line: There a couple of things I would change for my own project, but the fact is that you must investigate your hardware. I did ask about your development setup. If it's a PC board, show us a schematic and tell us about whether there is a ground plane, and tell us about the parts you used for Vcap and bypass capacitors. If it's a breadboard, describe power/ground wiring and tell us about bypassing and Vcap components. Regards, Dave |
|
|
|
只有小组成员才能发言,加入小组>>
5158 浏览 9 评论
1997 浏览 8 评论
1926 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3169 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2222 浏览 5 评论
724浏览 1评论
607浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
495浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
621浏览 0评论
520浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-19 17:28 , Processed in 1.453935 second(s), Total 97, Slave 80 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号