reading voltage level to indicate low or full voltage.

tesladude

New Member
I am making a small mobile sound system and I want to add an 08m2 to read the voltage off of one of my 3x4.2v batteries, I understand what I want it to do and everything I just need to know what command I can use to do this and how to use it as far up to as labeling a variable with the voltage so then I can take it from there and start on my if statments
 

westaust55

Moderator
You will need to use the READADC or REAdADC10 command to monitor the voltage level.

Be aware that you will need to set up a reference voltage for the ADC inputs (internally) if the voltage being monitored is the same as the PICAXE supply voltage as the default setup uses the supply voltage as the reference.
A scheme I have used in the past where the PICAXE supply voltage is being monitored is to use the forward volt drop across an external diode which is relatively constant but then the READADC values increase as the supply voltage drops.

When you say you are going to add an 08M2 is this the only PICAXE or is this a second PICAXE chip dedicated to the monitor of the supply voltage?
 

tesladude

New Member
Ya the 08m2 is the chip I will use to read the voltage, I want to use the 5v powering my 08m2 as the referance and then have about 3.5v as the low power led trigger.
So can you show me how to set up this reference voltage and just generally how to use it? Because I find the manual and list of general comands to be incredibly unhelpful and I need to hear it from someone so I can ask questions
 

Paix

Senior Member
Just pretend - read the Manual #2 for READADC or READADC10 figure out what you don't know and then ask your questions.

Code:
#picaxe 08M2
#terminal 4800

main:
  do
    pause 1000		; term takes time to initialise
			; how flat does your battery get in one second?
    readadc10 C.1,w1	; read ADC value into w1
    sertxd (#w1)	; transmit value 0 to 255 to computer
			; You figure how to represent this as 
			; your scaled voltage
  loop
			; just because I don't like goto
			; and it introduces you to something else!
This assumes that your AXE027 download cable is connected
 
Last edited:

tesladude

New Member
So is the voltage that is read labeled between 0 and 255 meaning I can be as acurate as 1/255 of my referance voltage?

Also all I need to do us have a red led go on when my voltage variable is less than a sertain amount of my reference voltage. So what is the sertxd and computer comunication for?
 

tesladude

New Member
Hey I just figured out what I need, because I am not storing or debuging the voltage or anything like that all I needed was readadc and it works perfectly. I have been useing picaxe only since christmas and have been trying for months todesign circuits or buy modules to check my battery voltage but then useing picaxe popped in my head. So thanks a bunch
 

Paix

Senior Member
The sertxd is there so that you know exactly what your circuit is reading. Once you are happy with the range of the data, then you can comment out that line or leave it for when you might want to plug up your computer, but it is unlikely that you would want a computer connected full time, just your LED, but for the initial insight it would be good. You can see what you are getting and are less likely to make mistakes.

Like my 0 to 255, which would have been better stated 0 to 1023. As you say, READADC will probably suffice and the code is much the same except that you would be assigning to a byte variable rather than a word variable . . . senior moments, sorry!

Using sertxd, just stick your byte variable in place of W1. The # causes the number to be converted to an ASCII string.

Have a play and extend some of the basic circuits incrementally and then add the bits together.
 

SAborn

Senior Member
I think what Paix was trying to say, is use READADC10, as increases the resolution from 255 to 1024.

This makes a big difference if you want to calibrate the reading, but for your single Red Led no calibration is required, just use debug to find the setting point.
 

Paix

Senior Member
ha ha, thanks. I don't like debug either, but prefer to use sertxd as it's less intrusive and tells me exactly what I want to know without having to figure it out from a more complex(?) display. I'm easily confused! :) (if that's what you want to believe)!
 

crowland

Member
The PicAxe uses the supply voltage as the analogue reference but also has a fixed internal voltage reference (1.2V IIRC) It's possible to read the internal voltage reference and use the value that you get - relative to the supply voltage - to determine the supply voltage.

I've put some code to do this in the code snippets section. I use it to keep an eye on the battery voltage and show a message when it's time to change the batteries.

Chris
 
Top