完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
大家好,为了控制PWM的占空比,我需要把一个10位的ADC输入转换成16位的值。我知道如何通过乘法和位移位把8位的值转换成10位的值,但是对于上面的问题我不能这样做。请给我一些有关此事的建议。还是我错过了一些东西,谢谢。
以上来自于百度翻译 以下为原文 Hi Everyone, I need to convert a 10-bit ADC input into 16-bit value for controlling the duty cycle of PWM. I know how to convert from 8-bit value to 10-bit value by multiplication and bit shifting but I could not do the same for the above problem. Please suggest me anything related to this. Or am I miss something in this. Thanks in Advance. |
|
相关推荐
11个回答
|
|
|
|
|
|
你想提供关于10位和16位值之间关系的更多细节吗?从10比特数转换到16比特数可以是许多不同的事情。-用0填充左6比特。-根据原始值用0或“1”扩展左6比特的符号。-使用线性关系(比例)与10比特值。-使用非线性关系与10位值…-……你到底想要什么?你的目的是什么?最佳选择
以上来自于百度翻译 以下为原文 Hi Would you like to provide more details on the relationship betwen the 10bit and the 16bit values? Converting from a 10bit number to a 16bit number can be a number of different things. - Padding the left 6 bits with "0". - Sign extending the left 6 bits with "0" or "1" depending on the original value. - Aplying a linear relation (proportion) to the 10bit value. - Aplying a non-linear relation to the 10bit value. -......... What exactly do you want? What is your purpose? Best regards Jorge |
|
|
|
或者只需将ADC切换到“左对齐”模式。:)
以上来自于百度翻译 以下为原文 or just switch the ADC to "left justified" mode. :) |
|
|
|
嗨,你可能会使它比它需要的更困难。许多ADC模块在SFR存储器中的2个8位寄存器中产生10位结果。XC8编译器连同设备支持文件lt;xc.h & gt;知道如何将ADC结果处理为16位值:如果ADC RE,您可以这样做:SULT寄存器放在不同的记忆库中,或者杂乱无章,上面的方法不起作用。你可能总是这样做:问候,Mysil。
以上来自于百度翻译 以下为原文 Hi, You may be making this more difficult than it need to be. Many ADC modules produce 10-bit results in 2 8-bit registers following each other in SFR memory. XC8 compiler together with device support file know how to deal with the ADC result as a 16 bit value already: You may do: #define SCALE 5000UL /* Note the characters UL following the scaling factor. * They are there to ask compiler to do 32bit multiplication when scaling. */ int millivolt, adcresult; adcresult = ADRES; millivolt = ADRES * SCALE >> 10; /* Scaling to millivolts for 10 bit ADC result when reference voltage is 5 V. */ If ADC result registers are placed in different memory banks, or otherwise jumbled, the above will not work. You may always do like this: int adcresult; adcresult = (ADRESH << 8) + ADRESL; /* Get ADC conversion result */ Regards, Mysil |
|
|
|
从10位到16位的转换应该类似于从8位到10位的转换。不同的是比例因子,我们确信。;)
以上来自于百度翻译 以下为原文 Converting from 10-bit to 16-bit should be similar as converting from 8-bit to 10-bit. The difference would be the scaling factor. That we are sure of. ;) |
|
|
|
如果希望获得大于10位分辨率的ADC读数,则可以添加(例如)4个连续读数,有效读取12位,并且如果信号有一些变化,则所得到的读数将提供这一点。若要从10位获得“全”16位,则需要添加64个读数。但是10位转换器的绝对精度和线性度将限制这种方法的有用性。大多数情况下,它只能提供一个更稳定的平均读数。而且,完整的16位只适用于相对较低的PWM频率,可能高达200-400Hz和32MHz时钟。
以上来自于百度翻译 以下为原文 If you want to get ADC readings with greater than 10 bits resolution, you might be able to add, say, 4 consecutive readings for effectively 12 bits, and if there is some variation in the signal, the resulting reading will provide that. To get a "full" 16 bits from 10 bits, you would need to add 64 readings. But the absolute accuracy and linearity of the 10 bit converter will limit the usefulness of such a method. Mostly it will just provide a more stable average reading. Also, the full 16 bits will only work for relatively low PWM frequencies, perhaps up to about 200-400 Hz with a 32 MHz clock. |
|
|
|
OP昨天又登录了,但是没有麻烦让我们知道我们的猜测是正确的。
以上来自于百度翻译 以下为原文 The OP logged in again yesterday, but did not bother letting us know which of our guesses was correct. |
|
|
|
我不明白。你能给我举个例子吗?我同意,但是我不会改变电位器输入的时间。我只需要改变占空比,如果我的时间周期为1us,如果我需要50%的占空比,我需要改变寄存器,使它是PWM1DCH=0x00和PWM1DCL=0xFF。它是如何工作的?我很抱歉。我正在结束我的SISTER考试,所以这是一个快速浏览论坛上的一些其他信息。我也需要测试别人的建议,我不能在不知道任何信息的情况下对某事发表评论。
以上来自于百度翻译 以下为原文 I don't understand it. could you please provide me an example for this. I agree but isn't it like I am gonna change the time period from potentiometer input. I just need to change the duty cycle if my time period is 1us if I need a duty cycle of 50% I need to change the register such that it is PWM1DCH=0x00 and PWM1DCL=0xFF. Isn't it how it works? I am sorry. I was having my end semester exams so it was a quick peek on the forum for some other information. I also need to test the things that other people's suggestions, I can't comment on something without knowing any information. |
|
|
|
如果你的PWM周期为1 USEC,那么50%占空比为500毫微秒。如果你有PWM时钟的FoSC=32兆赫,16个时钟脉冲将是50%。因此,16位的PWMDC寄存器对将具有0x00 10的值。
以上来自于百度翻译 以下为原文 If your PWM period is 1 uSec then a 50% duty cycle is 500 nSec. If you have FOSC = 32 MHz for the PWM clock, 16 clock pulses would be 50%. So the 16 bit PWMDC register pair would have a value of 0x0010. |
|
|
|
谢谢,PStechPaul。我理解这一点。我认为这解决了我的问题。
以上来自于百度翻译 以下为原文 Thanks, PStechPaul. I understood it. And I think this solves my problem. |
|
|
|
谢谢所有在这件事上提出建议和帮助我的人。
以上来自于百度翻译 以下为原文 Thanks for all those people who contributed their suggestion and helping me out in this matter. |
|
|
|
只有小组成员才能发言,加入小组>>
5163 浏览 9 评论
2000 浏览 8 评论
1928 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3172 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2226 浏览 5 评论
731浏览 1评论
614浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
503浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
630浏览 0评论
527浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-23 16:43 , Processed in 1.379001 second(s), Total 97, Slave 81 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号