问题描述
这是一个普遍的问题,我认为这可能是数学问题,但它是Arduino的平台。
This is a general question, I believe it maybe a math question but it is for the Arduino platform.
我做的一球悬浮项目,将让一个乒乓球suspeneded在管内的设定值时,球的位置读取,让相关的球位置的模拟电压的激光位置传感器。传感器输出是用于管的长度的操作范围pretty线性
I'm doing a ball levitation project that will keep a ping pong ball suspeneded at a setpoint in a tube, the balls position is read with a laser position sensor that gives an analog voltage related to the balls position. The sensor output is pretty linear for the operating range of the tube's length.
然后,我曾与PWM作为受控%的风扇,这是手动锅调整,我在一英寸增量标记在管的规模。
Then I have a fan controlled with PWM as a %, this is manually adjusted with a pot, and I marked a scale on the tube in one inch increments.
基本上我提出的传感器的电压输出值的表,与电动机为在管的不同位置的PWM%的值。
Basically I made a table of sensor voltage output values, related to PWM% values of the motor for different positions in the tube.
我提出有关这两个变量的曲线图,它是令人惊讶的pretty线性。我做了Excel中的趋势线,并得到y的直线方程= 3.0265X + 15.05
I made a graph relating the two variables and it is surprisingly pretty linear. I did a trendline in excel and got a line equation of Y = 3.0265X + 15.05
X是传感器的位置(单位为伏特)和Y是在%的PWM值,
X is the sensor position(in volts) and Y is the PWM value in %,
我在与从模拟引脚是在Arduino的0到1023的值以模拟电压,并将其与一个PWM麻烦的部分analogWrite到电机(从0到255之间的值)
The part I'm having trouble with is taking the analog voltage from the analog pin that is a value of 0 to 1023 in the arduino and relating it to a PWM to analogWrite to the motor (A value from 0 to 255).
我知道analogRead()是和ADC所以我所说的(5.0 * analogvalue)/ 1023 0〜1023值转换为电压;
I know the analogRead() is and ADC so do I convert the 0 to 1023 value to a voltage by (5.0 * analogvalue)/ 1023;
这会给我伏,但我不明白怎么怎么这与PWM,像传感器的电压在PWM到电动机的变化的变化。我觉得我在正确的轨道,但不点连接在一起。
That will give me volts, but I dont understand how how to relate this to PWM, like a change in sensor voltage to a change in PWM to the motor. I think I'm on the right track but not connecting the dots together.
任何帮助将AP preciated!
Any help will be appreciated!
感谢
推荐答案
一般而言,在PWM百分比直接相关的电源电压的电压。也就是说,如果你有一个5伏的Arduino和PWM比例为75%,输出应该是3.75伏,只要你有一个输出电路即能过滤出单个脉冲。
Generally speaking, the PWM percentage is directly related to the voltage of the supply voltage. That is, if you have a 5 volt Arduino, and the PWM percentage is 75%, the output should be 3.75 volts, provided you have a output circuit that is able to "filter" out the individual pulses.
请该PWM值在0到255的范围内,所以你需要分割的期望analogRead()值,这是范围为0至1023,由四个因素产生正确的输出电压采用PWM。
Keep in mind that the PWM values are in the range 0 to 255, so you'll need to divide the desired "analogRead()" value, which is in the range 0 to 1023, by a factor of four to produce the correct output voltage using PWM.
这篇关于与位置传感器电压,电机转速的PWM的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!