I am trying perform an analog to digital conversion on an external voltage source. I hooked up the ground of the external source to the power supply ground for the microcontroller, and the power from the external source to pin a7, and no luck. Should i connect it a different way or is it impossible to do this?

Thanks

Hello,

Which Orangutan are you using? What is the external voltage coming from, and what range of voltages do you expect to see from it? What program or code are you using to try to read the voltage? How is the result different than what you expect?

- Kevin

I am using the svp with 1284p, the external source is basically a 9 volt battery regulated to 5 volts with a 24 ohm resistor. I would expect to see the value jump to 255, using 8 bit for the converter, since it is 5 volts. The result does not change at all. Im sorry i do not know how to post the code the correct way.

``````while(1)
{sum = 0;
samples = 0;
avg = 0;
start_analog_conversion(PA7);  // start initial conversion
for(ia = 0; ia < 20; ia++)
{
while(analog_is_converting())
{
;
}
sum += analog_conversion_result();  // get result
start_analog_conversion(PA7);   // start next conversion
if (++samples == 20)           // if 20 samples have been taken...
{
avg = sum / 20;             // compute 20-sample average of ADC result
samples = 0;
sum = 0;}
``````

Do you have one side of a 24 ohm resistor connected to the positive terminal of the 9 V battery and the other side of the resistor connected to the Orangutan’s input pin? This is not a good way to “regulate” the voltage. Since the input pin is in a high-impedance state, very little current is flowing through the resistor, which means the voltage drop across it is very small. In effect, you are exposing the input to nearly the full 9 volts, and since the absolute maximum voltage on the pin is not supposed to exceed 5.5 V (Vcc+0.5), it is possible that you have already damaged that pin.

For a high-impedance input, a voltage divider is a more appropriate way to reduce your 0-9 V range to a 0-5 V (or less) range.

Your code looks okay, though it seems like you are missing a few closing braces (I’m guessing you just missed selecting them while copying).

Could you try using a different ADC pin on the Orangutan and measuring a voltage that is definitely in the range of 0-5 V? (For example, you could try measuring a 1.5 V battery.)

- Kevin

im sorry about the confusion i shouldve made it clearer. it is regulated by a regulator which brings it down to 5 volts, but there is a thevenin equivalent resistance of 24 ohms after the regulator. Does it matter what ground i connect it to? i tried connecting it to the grounds that are provided on the blocks and i also tried connecting it to the power supply ground.

Should this be working? Or was the idea of trying it this way just wrong?

I hook up an ir sensor to that port and with the same code i get accurate readings from the sensor. Then i try the voltage source and nothing.

Hello.

Have you independently verified (e.g., with a multimeter) that your battery isn’t dead and that the regulator is working and outputting what you think it is? What are you using for a regulator and how do you have it connected? Can you post a simple schematic of your setup?

- Ben

Turns out that one of the wires i was using did not have continuity. It was broken somewhere along the line. I replaced the broken wire and it started working perfect. Thanks for all yalls help guys i appreciate it.

I am glad to hear you figured it out. Thanks for letting us know what the problem was.

- Kevin