Software > Software

Measure Voltage

(1/1)

123eric:
I am trying to measure the voltage on a pin on my pic16f870 but am having some problems in doing so, and cant find what I am lookin for online. I have a variable resistor hooked up to a voltage divider so that I can vary the voltage from 0 to 2.5v. This is hooked up to pin RC3 on the microcontroller. So far this is what I have for my picbasic code.

loop:
peek 7, b0
let bit3=b1

if b1<50 then a
if b1<100 then b
if b1<150 then C
if b1<200 then d
if b1<255 then E
goto loop.

A b c d e will make lights blink at a different speed depending on the voltage. But they are not doing this.

Thanks for any help.

Try simplifying your code so that you can narrow down where the problem is.

Do something very simple, like:

if b1<50 then LED off
if b1>49 then LED on

This way you know its not your blinking speed code that isnt wrong.

Its also good to check it with a multimeter to make sure your wiring isnt wrong.

I am not familiar with picbasic code, but is this line correct?
let bit3=b1

at least in C, that line should be written as:
let b1=bit3

hope that helps . . .

JonHylands:
Well, to start with, pin RC3 is a digital I/O pin, so you're not going to get any voltage other than 0 or 5 volts out of it.

If you want to measure voltage, you need to use one of the analog input pins, which typically are on port A, and have names like AN0 and so on. Once you have the hardware plugged in to the correct pin, you will need to use the A/D converter to read the voltage, which is more involved than just assigning a variable - check your compiler manual...

- Jon