完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
大家好,我知道PWM分辨率是如何“罚款”你可以控制占空比。我有点困惑,我有一个PIC18F45 50运行在48 MHz,一个31250Hz周期,运行定时器2与A / 4预分频器和PR2=95。这使我能够控制的职责,最大的小数值的CCPR1L:CCP15:4=384。我认为这是9位分辨率是正确的吗?我应该能用10位分辨率达到1023吗?PWM公式表示的最大分辨率是10.585(10位)……有人能帮我把脑袋转过来吗?善耿
以上来自于百度翻译 以下为原文 Hello all. I understand that PWM resolution is how "fine" you can control the duty cycle. I am a bit confused though, I have a PIC18F4550 running at 48Mhz, a 31250Hz Period, running timer 2 with a /4 Prescaler and PR2 = 95. This allows me to control the duty with a maximum decimal value of CCPR1L:CCP1CON<5:4> = 384. Am I right in thinking this is 9 bit resolution? as I should be able to get to 1023 with 10 bit resolution? The PWM formula states the max resolution I have is 10.585 (10 bit)... Can somebody help getting my head round it? Kind Regards Gunn |
|
相关推荐
11个回答
|
|
10位是你能得到的最大值,但在较低的频率。
以上来自于百度翻译 以下为原文 10bits is the max you could get, but at a lower frequency |
|
|
|
谢谢你的回复。我知道我能得到的最大值是10位(PIC有一个10位PWM模块)。用Fosc的48 MHz和31250Hz的周期,PWM公式说明我已经有了10位的分辨率。CpP1L:Cp1Con & lt;5:4的十进制值表示,我在384时命中100%,但我肯定在1023时命中100%的责任。顾恩
以上来自于百度翻译 以下为原文 Thank you for the reply. I understand the maximum I can get is 10 bit (the PIC has a 10bit PWM module). With a Fosc of 48Mhz and a period of 31250Hz, the PWM formula states that I already have a resolution of 10bit. The decimal value of CCPR1L:CCP1CON<5:4> states that I hit 100% duty at 384, but surely I should hit 100% duty at 1023? Regards Gunn |
|
|
|
我不太了解那个PIC的模块,我只是用它来做简单的蜂鸣器。它意味着“你在384的时候得到100%的任务”,因为你必须设置PR寄存器到384,才能达到期望的频率。
以上来自于百度翻译 以下为原文 I don't know much that module from that PIC , I only used it for simple buzzers. Could it mean that "you get 100% duty at 384" because you had to set PR register to 384, in order to achieve the desired frequency? |
|
|
|
在大多数8位PIC器件中,PWM是通过使用8位定时器和在指令计数器中的2个附加位或在计时器中的预分频器来实现的。为了获得最大分辨率,需要使用定时器周期:PR2=255;对于具有1024个步骤的PWM周期,以及占空比,使用CCPR1L为8个B。它和2位DC1B1:DC1B0在CCP1CON寄存器中,只有4个不同值的CCP1CON寄存器,代表PWM分辨率最小的步骤:0x0f、0x1f、0x2f和0x3f。然后8个高位占空比进入CCPR1L,最大值为255个十进制,但在CCPR1L中的值更高。n在PR2中的值将不起作用,除了保持输出在所有时间之外。通过设置PR2=95,将可能的分辨率从1/1024降低到:1(/(95 +1)*4)=1/384,约8±1/2比特。根据您的要求,选择特定的PWM重复频率将放置。可以得到什么样的分辨率的限制。你的应用可以容忍更高或更低的PWM重复频率吗?问候,Mysil
以上来自于百度翻译 以下为原文 Hi, In most 8 bit PIC devices, PWM is arranged by using a 8 bit timer, and 2 additional bits in the instruction counter or in prescaler in the timer. To obtain the maximum resolution, you will need to use Timer period: PR2 = 255; for a PWM period with 1024 steps, and for Duty Cycle, use CCPR1L for 8 bits, and 2 bits DC1B1:DC1B0 in CCP1CON register. There will be only 4 different values of CCP1CON register, representing the smallest steps in PWM resolution: 0x0F, 0x1F, 0x2F and 0x3F. Then the 8 high bits of Duty Cycle go in CCPR1L, with a maximum value of 255 decimal, but values in CCPR1L higher than the value in PR2 will have no effect, other than keeping the output ON all the time. By setting PR2 = 95, you have reduced the possible resolution from 1/1024 to: 1/((95+1)*4) = 1/384, which is about 8 + 1/2 bits. Depending on your requirements, selecting a specific PWM repeat frequency will place restrictions on what resolution may be obtained. Could your application tolerate a higher or lower PWM repeat frequency? Regards, Mysil |
|
|
|
跳到PIC上基于Time2的PWM的一个非常模糊的点:当占空比必须达到100%,如果从0到1020时,控制的实际范围。这是PWM占空比的结果仅当CCPXRL寄存器设置为大于PR2值的值时为100%。这意味着,在CPCXCON位的最后4个计数LT;5:4&GT不影响占空比。当CCPxRL等于PR2和CCPXCON位LT;5:4和GT的情况下,都是PWM输出的一个结果,该PWM输出是Time2的四分之一时钟,占100%占空比。如果你能处理从0到99.90234375%的PWM占空比,那么当PR2中的值为0xFF时,控制范围为0到1023。星期五是国际NIT选择器。:)
以上来自于百度翻译 以下为原文 To jump on a very obscure point about the TIMER2 based PWM in the PIC the actual range of control when the duty cycle must reach 100% if from 0 to 1020. This is a consequence of the PWM duty cycle is only at 100% when CCPxRL register can be set to a value GREATER than the value of PR2. This means that those last 4 counts in CCPxCON bits <5:4> do not affect the duty cycle. The case when CCPxRL is EQUAL to PR2 and CCPxCON bits <5:4> are both one results in a PWM output that is one quarter clock of TIMER2 short of a 100% duty cycle. If you can deal with a PWM duty cycle from 0 to 99.90234375% then you get a control range of 0 to 1023 when the value in PR2 is 0xFF. Today is international nit picker Friday. :) |
|
|
|
在数据表中选择另一个NIT,像许多旧设备一样,这是一个PWM分辨率的错误方程。正确的等式ISlog((PR2+1)*4)/log(2)一般,如果你需要特定的FPWM和分辨率,你必须向后工作,以确定Fosc应该用PIC使用什么。
以上来自于百度翻译 以下为原文 Picking another nit in the data sheet, like many older devices, this one has the wrong equation for PWM resolution. The correct equation is log((PR2 + 1) * 4) / log(2) Generally, if you need a particular Fpwm and resolution, you have to work backwards from that to determine what Fosc you should use with the PIC. |
|
|
|
在这一点上,你必须误用公式。Mysil清楚地总结了为什么只有当PR2=0xFF时才能得到10位分辨率。这纯粹是由PR2决定的,而不是由频率决定的。频率是PR2、分频器和主振荡器的副作用。
以上来自于百度翻译 以下为原文 You must be misapplying the formula at this point. Mysil has clearly summed up why you can only ever get 10 bit resolution when PR2 = 0xFF. This is purely determined by PR2, not by the frequency. The frequency is a side effect of PR2, your dividers, and master oscillator. |
|
|
|
为了稍微扩展丹点,如果你愿意绕过PWM,在100%种情况下,你可以得到1024分辨率(实际上1025计数0%和100%)。如果不这样做,他是100%(如果我可以使用这个范围)是正确的。出于代码简单的原因,我保持占空比为16位,范围为0到32768(0xOMW-0x8000)。当将占空比应用到PWM时,我检查比特15(字节1,比特7),如果调制器开启,则将调制器关断。我有一套。【注意:使用PPS启用的芯片,我必须将输出引脚重新路由到端口/ LAT -使调制器关闭,但不这样做。]这可能不适用于大多数应用程序,但它恰巧简化了我的代码,使我能够减少功率使用时,占空比为100%(非常常见的事件)。我的用法
以上来自于百度翻译 以下为原文 To expand on Dan's point slightly, you can get 1024 resolution (actually 1025 counting 0% and 100%) if you are willing to bypass the PWM for the 100% case. Without doing that, he's 100% (if I can use that range) correct. For reasons of code simplicity, I keep by Duty Cycle in 16 bits with a range of 0 - 32768 (0x0000 - 0x8000). When applying the duty cycle to the PWM, I check bit 15 (byte 1, bit 7) and turn the modulator off if it's on. I have the LAT bit set. [Note: with PPS-enabled chips, I have to re-route the output pin to the port/lat - turning the modulator off doesn't do that.] This may not be needed for most applications, but it happens to simplify my code and enable me to reduce the power usage a bit when Duty Cycle is 100% (a very common occurrence for my usage). GP |
|
|
|
谢谢你的回复。我的应用程序不是频率特定的,只需要在20kHz以上。所以,基本上我只需要设置PR2=255,改变预分频器以获得高于20kHz的频率。善耿
以上来自于百度翻译 以下为原文 Thanks for the replies. My application isn't frequency specific, just needs to be above 20kHz. So essentially I just need to set PR2 = 255 and change the prescaler to get a frequency above 20kHz? Kind regards Gunn |
|
|
|
是的,你可以选择三个PWM频率:FoSc/1024,OFSC/4096,或Fosc / 16384。
以上来自于百度翻译 以下为原文 Yes, you have a choice of three PWM frequencies: Fosc / 1024, Fosc / 4096, or Fosc / 16384. |
|
|
|
|
|
|
|
只有小组成员才能发言,加入小组>>
5289 浏览 9 评论
2059 浏览 8 评论
1969 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3233 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2277 浏览 5 评论
824浏览 1评论
710浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
654浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
710浏览 0评论
609浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2025-1-14 07:59 , Processed in 1.267590 second(s), Total 95, Slave 79 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (威廉希尔官方网站 图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号