完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
您好,我正在与PIC24FJ128DA210一起工作,我有一些关于如何正确配置PWM与输出比较模块和定时器2的问题。特殊信息:FoSC=8MHz的PLL模式启用(它可能是32 MHz)PWM目标频率=88HZI在数据表中看到:- OCxR是寄存器THAT控制占空比——OCxRS是控制周期的寄存器,但是配置time2和选择时钟源似乎是PWM的一个整体周期。所以,我的问题是:每个寄存器都要设置哪一个值才能正常工作?我从PIC24F系列参考得到的计算结果是:PWM周期=[(PRY)+1 ] *Test*(TMRY PrimCale值),从这里我首先在PRIM2配置上设置PR2目标值,我设定PWM周期(我的目标频率)为48 8Hz。在OC1R寄存器上设置最大周期?然后,我有:PWM频率=1 / [ PWM周期],我不知道在哪里使用它…最后我们的PWM占空比是用最大PWM分辨率(比特)=(Log10(fCy/(fPWM*(定时器预缩放值))/Log10^ 2)计算的),它给了我最大的比特=15000。正确的PWM模块?这让我很困惑,我真的想知道它是如何工作的。这是我的代码,你会注意到我需要修复OC1R和OC1RS的值。谢谢你的时间,我希望有一个答复来澄清我所拥有的这个问题。
以上来自于百度翻译 以下为原文 Hello, I'm working with the PIC24FJ128DA210 and I have some questions about how to configure properly the PWM with the Output Compare module and Timer 2. Special info: Fosc = 8MHz with PLL mode enabled (It might be 32MHz) PWM Target frequency = 488Hz I saw in the datasheet that: - OCxR is the register that controls the duty cycle - OCxRS is the register that controls the period However, it seems that configuring Timer2 and selecting as clock source is used as an overall Period for the PWM. So, my question is: Which value do I have to set to each register to work properly? I get the calculations from the PIC24F Family Reference an states that: PWM Period = [(PRy) + 1] * TCY * (TMRy Prescale Value) From here I have first the PR2 Target value to be set on the Timer2 configuration, I set a PWM Period (my target frequency) as 488Hz. Is the PR2 the maximum value that I have to set the Maximum period on the OC1R Register? Then, I have: PWM Frequency = 1/[PWM Period] Which I don't know where to use it... Finally we have the PWM Duty Cycle which is calculated with: Max PWM Resolution (bits) = (log10(FCY/(Fpwm * (timer Prescale Value)))/log10 ^2) Which gave me the maximum bits = 15.00083 Where do I put each value to configure properly the PWM module? This is confusing me a lot, and I really want to learn how it works. Here is my code and you will note that I need to fix the OC1R and OC1RS values selected. Thanks for your time and I hope for a reply to clear this issue that I have. // PWM LEVEL Output // 100% approx = 32786.9 or 15.00083 bits // LEVEL_1 is 20 % PWM Output #define LEVEL_1 6557 // LEVEL_2 is 50 % PWM Output #define LEVEL_2 16394 // LEVEL_3 is 80 % PWM Output #define LEVEL_3 26230 // LEVEL_4 is 95 % PWM Output #define LEVEL_4 31147 void Timer2_ForPWM() { // Set Timerx and Timery act as two 16bit timers T2CONbits.T32 = 0; // Set Clock Prescale 1:1 T2CONbits.TCKPS = 0b00; // Internal clock is selected (FOSC/2) T2CONbits.TCS = 0; // Gated time accumulation disabled T2CONbits.TGATE = 0; // PR2 = (2.05mS/62.5nS) - 1 = 32799 = 0x801F // Period = 2.05mS = 488Hz // Tcy = 62.5nS PR2 = 0x801F; // Initialize TMR2 count is 0 TMR2 = 0; // Start the 16bit Timerx T2CONbits.TON = 1; } void PWM_Init() { // Unlocking PPS __builtin_write_OSCCONL(OSCCON & 0xbf); // RD8->OC1:OC1; RPOR1bits.RP2R = 0x0012; // Locking PPS __builtin_write_OSCCONL(OSCCON | 0x40); // Duty cycle = OC1RS / (PR2+1) = 50 % OC1RS = LEVEL_3; OC1R = LEVEL_3; // Select the current OC1 as the synchronization source OC1CON2bits.SYNCSEL = 0b11111; // Synchronize OC1 with the source designated by the SYNCSEL bits OC1CON2bits.OCTRIG = 0; // OC1 Timer2 Selected as clock source OC1CON1bits.OCTSEL = 0b000; // Edge-Aligned PWM mode on OC1 OC1CON1bits.OCM = 0b110; // The Fault input enable bits are disabled OC1CON1bits.ENFLT = 0b000; // The Fault status bits are disabled OC1CON1bits.OCFLT = 0b000; } |
|
相关推荐
7个回答
|
|
当OCM=6时,CurryCysRISCOXR//(PR2+ 1)。当你需要改变OCxR时,你不会直接这样做。相反,您将值写入OCXRS。这是必要的,以确保OCxR在周期的中间没有得到更新。当计时器翻转时,模块自动将值从OCxRS移到OCxR。
以上来自于百度翻译 以下为原文 When OCM = 6, the duty cycle is OCxR/(PR2+1). When you need to change OCxR, you don't do this directly. Instead, you write value to OCxRS. This is necessary to make sure OCxR doesn't get updated in the middle of the cycle.When the timer rolls over, the module automatically moves value from OCxRS to OCxR. |
|
|
|
这是一件让我困惑的事情,因为在PIC24FJ128DA210数据表状态下:
以上来自于百度翻译 以下为原文 This is a thing that confuses me because in the PIC24FJ128DA210 datasheet state: |
|
|
|
这取决于你使用的模式。有些模式同时使用OCxR和OCXRS,但是您的OCXR只使用占空比OCXR和OXXRIS仅对OCXR的访问。
以上来自于百度翻译 以下为原文 It depends on the mode you use. Some modes use both OCxR and OCxRS, but yours only uses OCxR for duty cycle and OCxRS is only a buffered access to OCxR. |
|
|
|
好的,我明白了。但是,我仍然在看数据表,这是PWM模式的14.3个部分:这是你之前提到的同样的事情吗?在它们被单独配置的情况下:根据计算,我是否可以将SETCO1R(占空比)=0到15比特(0—32768)之间的任何值?OC1RS(期望周期)=0到PR2之间的任何值(0—32786),根据上面的计算?
以上来自于百度翻译 以下为原文 Ok, I see. However, I'm still looking the datasheet and this is the 14.3 section of PWM mode: This is the same thing that you mentioned before? In the case that they are configured separately: Could I set OC1R (Duty Cycle) = Any value between 0 to 15bits (0 - 32768) according with the calculations? OC1RS (Desired Period) = Any value between 0 to PR2 (0 - 32786) according with the calculations from above? |
|
|
|
你说得对。DA有一个更新的OC模块。该模块具有内置计时器,因此不使用外部计时器进行计数。这段时间可能来源于SysCSEL寄存器所确定的各种来源。看起来混淆是因为你读了旧OC模块的FRM第16章。您需要第68章的新的OC模块-文件DS7000 05159A。
以上来自于百度翻译 以下为原文 You're right. DA has a newer OC module. This module has a built-in timer and thus doesn't use external timer for counting. The period may come from a variety of sources as determined by the SYNCSEL register. Looks like the confusion happens because you read the FRM chapter 16 for the old OC module. You need chapter 68 for the new OC module - document DS70005159A. |
|
|
|
在这种情况下,我将假定OC1R和OC1RS上设置的值与上述类似。但是,我需要将Sycel寄存器更改为0B01100,以选择定时器2作为同步源。在位寄存器OCTSEL中,计时器2也作为时钟源,我不KNO。如果有了这个东西,它就不需要改变从0B11111到0B01100的Sycel寄存器。
以上来自于百度翻译 以下为原文 Well In that case I will asume that the values that could be set on OC1R and OC1RS are like the above. However, I would need to change the SYNCEL Register to 0b01100 to select the timer 2 as the synchronization source. In the bit register OCTSEL is timer 2 reffered also as a clock source, I don't know if with this thing set, it doesn't need to be changed the SYNCEL register from 0b11111 to 0b01100 |
|
|
|
OCTSEL只选择时钟源。定时器2未被真正使用。仅使用它的时钟源来对内部OC时钟进行计时。SysCSEL选择复位内部OcTIMER(从而设置周期)的源。0B11111将选择OCXRS,0xB01100将选择定时器2。因此,如果您希望OCxRS设置周期,SysCSEL应该是0B11111。
以上来自于百度翻译 以下为原文 OCTSEL only selects the clock source. Timer 2 is not really used. Only its clock source is used to clock the internal OC timer. SYNCSEL selects the source which resets the internal OC timer (thereby setting the period). 0b11111 will select OCxRS, 0xb01100 will select Timer 2. So, if you want OCxRS to set the period, SYNCSEL should be 0b11111. |
|
|
|
只有小组成员才能发言,加入小组>>
5250 浏览 9 评论
2037 浏览 8 评论
1958 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3218 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2266 浏览 5 评论
790浏览 1评论
682浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
612浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
686浏览 0评论
584浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-29 13:36 , Processed in 1.566731 second(s), Total 88, Slave 72 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号