Reading Voltage Value to Picaxe

bbrrww

New Member
Hi, I am an a-level electronics student and i'm a little stuck on my project...

I have been trying to read the value of a varying voltage on a adc pin of my picaxe to a variable (lable?) using the readadc function but i haven't got it to work as yet.

Any help or suggestions would be really appreciated,

Cheers, Oliver
 

BeanieBots

Moderator
Well, the command line is simple enough.
ReadADC pin#,var
So what exactly doesn't work?

How fast and over what range is "varying".
What are you expecting to see and what are you actually getting?

It would probably also be useful to know which PICAXE you are using.
 

womai

Senior Member
Also, please post the code that you have so far, state which Picaxe you are using (08M or other?), along with a description of what signal exactly you are trying to measure, and if possible a schematic sketch of your hookuo (or even better, use a digital camera to snap a picture!). Debugging code is incomparably easier when actually seeing it, and the same goes for the hardware ;)

Wolfgang
 

jglenn

Senior Member
I am playing around with my P. Anderson 18X protoboard, would love to see a sample of how to input an 8 bit pot value, and monitor with with a serial output to the screen, is there a debug mode that will work in real time? Just starting to use the programming software, only blinked a LED so far.
 

BeanieBots

Moderator
simple enough, especially if you read the manual.

main:
readadc 1,b0
sertxd b0 'send value to terminal screen
debug 'see all variables in editor
goto main 'keep reading and displaying
 

jglenn

Senior Member
Thanks, I did not know about AXE001-3, been using just a TAB book: Programming and customizing the PICAXE, lot of examples but not enough detail of the nuts and bolts. Have to get those docs printed out, hate reading on the screen. Going to try that code after I solder a pot on. I have an app that I hope 8 bits will be enough for, the 10 bit seems harder to use, since 2 bytes are needed per sample, I guess the Basic will treat that as a variable, but won't that take more processing time? That is, if I have a program sampling 8 bit inputs, won't that by nature run faster than one using 10 bit inputs?
 

eclectic

Moderator
@jglenn

Please read manual 2,

pages131 - 133

page 160

e

PS. I also own that book.
Leave it alone, until you get a grasp of the "real" manuals. :)
 

Dippy

Moderator
I'd get to grips with the basics first, including the meaning of variable, before worrying about speed.

"That is, if I have a program sampling 8 bit inputs, won't that by nature run faster than one using 10 bit inputs? "
- I dunno.
If you are using the 18X (based on a PIC16F88) it only has a 10 bit ADC, so the actual nitty-gritty conversion makes no difference.
I don't know how the PICAXE firmware handles the ADRESL:ADRESH registers after the conversion, but I suspect the difference will be small enough for you not to worry about. ;)

But, for economy of variable usage and subsequent operations, use bytes where possible if the 8 bit resolution is OK.
 

jglenn

Senior Member
It says there is a syntax error in this line:

sertxd b0 'send value to terminal screen

This is fun so far. The command looks right, do you have to declare variables at the beginning? I am running ver. 5.1.5. Is that too old?
 

eclectic

Moderator
It says there is a syntax error in this line:

sertxd b0 'send value to terminal screen

This is fun so far. The command looks right, do you have to declare variables at the beginning? I am running ver. 5.1.5. Is that too old?
See Man. 2, p 160, for examples of sertxd.

AND, update to ver. 5.21.

e
 

jglenn

Senior Member
My manual is older, but I found the section on sertxd. I would think this would work but it doesn't:

sertxd (#b0) 'send value to terminal screen

The brackets are a mystery to me. I know that b0 is a word variable, so I am learning something. I will read the entire manuals after I get a hard copy, my printer broke. Please note I am not a real programmer, and this is a puzzle to me. I am using the PICAXE to make the software EASIER! I have done some basic awhile ago with the AIM65, and do a bit of pic machine code, but serial is tough that way. Don't I need to convert it to ASCII, with the # sign?
 

eclectic

Moderator
Please READ, then try the code in

Manual 2, page 160

main:
for b1 = 0 to 63 ‘ start a loop
sertxd(“The value of b1 is ”,#b1,13,10)
pause 1000
next b1 ‘ next loop

And, for even more fun,

try the program in the simulator.
(Yellow arrow in PE).

e
 

jglenn

Senior Member
I tried doing a syntax check on this patch of code that is right from your app note, still trips on the sertxd line.

main:
for b1=0 to 63
sertxd("value is",#b1,13,10)
pause 1000
next b1
 

jglenn

Senior Member
Yes, I copied your code exactly, still has error. Note I see a message on the bottom of my screen that says PICAXE 28, I am using an 18X. How do I change that? Maybe that is the problem. Sorry, new at this, I WILL READ more about it..:eek:
 

jglenn

Senior Member
There is something wrong with your quote symbol, showing up as a black bar. This gets thru with no errors:

main:
for b1=0 to 63
sertxd("value is",#b1,13,10)
pause 1000
next b1
 

eclectic

Moderator
Yes, I copied your code exactly, still has error. Note I see a message on the bottom of my screen that says PICAXE 28, I am using an 18X. How do I change that? Maybe that is the problem. Sorry, new at this, I WILL READ more about it..:eek:
Look up #picaxe in PDF search.

e
 

Attachments

jglenn

Senior Member
I understand that converts it to ascii. Ok, finally, this works, I can see the bcd pot value in the screen readout. Cool.

main:
readadc 1,b0
sertxd (b0) 'send value to terminal screen
debug 'see all variables in editor
goto main 'keep reading and displaying
 

bbrrww

New Member
Thanks, here's some more information which I hope will help

I am using a picaxe 18X

The signal I'm trying to measure is from an mp3 player with the aim of being able to display the output volume in db on an LCD display. I did some experiments and discovered that if I use (10.7 * ln(Input Voltage)) + 94.4 I get the output volume in decibels. Now I'm trying to use a picaxe to measure the voltage and display the appropriate figure.

The coding I have done so far is:
init: pause 500
main: b1 = 0
readadc 0,b1
serout 7,N2400,(254,1)
Pause 30
serout 7,N2400,(254,128)
serout 7,N2400,("Output =")
serout 7,N2400,(254,192)
serout 7,N2400,(#b1)
Pause 1000
goto main

The problem is that even with no input the display just shows random numbers and doesn't respond to any inputs. Even when I use a variable resistor to make a potential divider it still wont respond to the input voltage.

My plan is simply to join the amplified output of the mp3 to the adc0 pin but I don't know if this is entirely correct.

I'm not sure if the picture I've attached is any help but I attached it just in case.

Really grateful for any help you can provide :)

 

eclectic

Moderator
Some quick points.

1. It's easier to post jpg pictures direct on the Forum.
Look for "Manage Attachments" in the Reply menu.

2. It looks like you're using the ADC0 input om the AXE090.

For the 18X, you need IN0

3. Can you provide a sketch / circuit diagram / description
of the connection between the MP3 and the AXE090?

It looks like you've only got one wire connected.

e
 

BeanieBots

Moderator
OK, now explained what you are trying to do, it is much clearer why "it doesn't work".

You can't feed sound signals direct into a PICAXE ADC and expect to get anything other than random numbers. (as you've already found out).

First, you need to pass it through a detector circuit.
This can be very simple to do. Just feed the signal via a diode and resistor into a capacitor. Also fit a resistor across the capacitor.

Don't know the maginitude of your signal or the response time you want so it's hard to advise on values but to get you going, try these values.

Diode+1k into 100uF//10k to ADC input.
 

hippy

Ex-Staff (retired)
Even when I use a variable resistor to make a potential divider it still wont respond to the input voltage.
Converting an audio input to give an analogue indication of volume level is more than simply connecting the audio to an ADC input. Depending on what you want to display it could be as simple as an RC network although it might require some op-amp buffering.

An accurate display of level would depend on how you defined what it was you were showing and may require more complicated signal processing and software to match what a commercial display would show for the same input. The PICAXE may not have the analogue bandwidth to determine an accurate dB - and the response rate of the LCD limits that further - but it should be possible to achieve a display which is suitable.

Using a two-line, 16 character LCD gives a very nice, 80 step bar graph, stereo level meter, even better with a peak indicator as well. With just 7 steps given by a single character a 16 channel vertical bar graph meter even looks quite impressive.

An interesting article on audio metering with some circuits can be found here -

http://www.ethanwiner.com/meters.html
 

Dippy

Moderator
Don't suppose you can use the 'Manage Attachments' for images could you please ?

I get fed up with being sent off to Party Poker or some other carp like that.

Thats a good article hippy. A nice 16x2 bar chart will look nice.

BB suggests a nice simple approach which is a good start as I assume you are on the first rung of the electronics ladder?
 
Top