go_away

Author Topic: Measure Voltage  (Read 2545 times)

0 Members and 1 Guest are viewing this topic.

Offline 123ericTopic starter

  • Beginner
  • *
  • Posts: 5
  • Helpful? 0
Measure Voltage
« on: May 19, 2007, 02:10:45 PM »
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.


Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,660
  • Helpful? 169
    • Society of Robots
Re: Measure Voltage
« Reply #1 on: May 20, 2007, 01:38:23 PM »
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 . . .

Offline JonHylands

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 562
  • Helpful? 3
  • Robot Builder/ Software Developer
Re: Measure Voltage
« Reply #2 on: May 20, 2007, 03:45:04 PM »
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

 


Get Your Ad Here

data_list