View Full Version : Analog vs Digital inputs?
11-08-2002, 12:12 PM
The way I understand it, you can wire a switch into the digital input on the RC as a rc_sw# and then it disables a PWM or relay.
Also, I see that you can wire a sensor into a analog input as sensor#
The problem is, I can't figure out what the analog inputs output :)
If anyone can clarify this, i would appreciate it.
11-08-2002, 01:06 PM
analog inputs output
Analog inputs if I understande correctly output a varying voltage. For example a potemimenter(spelling really badly) is a analog input. As you turn the pot it's voltage varies. This is a analog device. Digital devices usually are either on or off like a switch. I hope this answers your question.
11-08-2002, 01:14 PM
But where does the output of variable voltage go? what is it used for and how is it programmed?
11-08-2002, 01:27 PM
Thats were I get lost:). An analog to digital converter will convert the analog voltage into a digital signal or a comparator can read the voltage off the circuit and will go a high state if the voltage is a certain level. Basically I think you need to convert the analog into digital signal before you can do anything.
11-08-2002, 01:38 PM
By themselves, neither switches or sensors do anything. It is only in the programming that you can make something happen (or not happen) as a result of the values of a switch or sensor.
The way the switches "disable" a relay or speed controller is because the default code has them set up that way. Once you change the default code, you can have these things do anything you want.
11-08-2002, 02:18 PM
I believe the output voltage from an analog sensor doesn't go anywhere in particular, it's just used in "if, then" logic sequences within the PBASIC processor, such that "If <condition exists> then <result>, much like the digital sensors, if sw_1 = on, then motor1= off, etc. but rather, if var=127 then pwm1=127, if var=254 then pwm1=254, etc. The changes in voltage are registered as variables in the programming, defined based on the SERIN command upon every program iteration/repetition (which is why it sits at the top of the main program loop). The serin captures whatever the voltage happens to be upon it's execution, whether a sensor (gyrochip) or a potentiometer, and saves it in the program as a variable, until the program loops and it is replaced by the same serin command. This loop cycles anywhere from 50-80 times per second, depending on the length and complexity of the program, resulting in what feels like a real time translation of analog data into action, when really it's cycle based.
Hope that helps.
11-08-2002, 04:23 PM
The output of an analog would go to something like a speed controller to change the speed of one of your motors. A digital output would likely go to a spike which is ON FWD, OFF, or ON REV.
The output from the IFI controller is not an analog voltage signal as one might think but rather a PWM (Pulse width Modulated) signal that has a varied pulse width to distinguish the analog signal. The victor(or RC Servo) will then take this signal and convert it to a voltage for the motor or a position for the servo.
PULSE WIDTH ANGLE COMMENT
0.6 mSec -45 degrees minimum pulse length
1.5 mSec 0 degrees center position
2.4 mSec -45 degrees maximum pulse length
Hope this helps
11-08-2002, 05:40 PM
Originally posted by Marc P.
if var=127 then pwm1=127, if var=254 then pwm1=254
Unfortunately, this type of syntax does not work. The only thing after the "then" can be a label to go to if the condition is true. For example:
if (sensor1<127) then dontZeroPWM1
With this code, anytime sensor1 is greater than or equal to 127, PWM1 will be set to 127. When sensor1 is less than 127, the condition is true and the code skips the line that would normally set PWM1.
This is by far one of the most confusing parts of PBASIC and is the reason why many times you will find yourself writing "if not" instead of just plain "if." Once you are able to think of "if" statements as being used to skip portions of code, everything becomes much easier.
11-08-2002, 09:18 PM
I realize this, but for the purposes of explanation, it's easier to understand. Virtually none of the sensors are perfectly calibrated to the same scale as the PWM, and often a complex mathematical equation is necessary to make it function even remotely proper. My purpose was not to state proper syntax, but answer the original question via theoretical explanation.
vBulletin® v3.6.4, Copyright ©2000-2014, Jelsoft Enterprises Ltd.