Under clocking does it affect readadc

Protolisk

Member
I heard that you can under clock the picaxe to run at lower voltage. Does under clocking give it a stable voltage? The picaxe 08m uses its source power as a reference when doing readadc. Will it give the same value if I use a voltage between 2.8v-5v?

For example i want to read the voltage of a 1.5v pot(not sure how many ohms it is). If I run the picaxe normally then the readadc value of the pot will change depending on the level of my batteries. If I under clock the PICAXE will I get the same value even if my batteries are low or fully charged?
 

BCJKiwi

Senior Member
No,

'Under clocking' refers to reducing the (clock) speed of the chip - not to voltage. Perhaps the term used should be 'reduced supply voltage'?

Readadc gives a reading of 255 when the readadc input = the supply voltage.
readadc = supply @ supply of 5V = 255, readadc = supply @ supply of 2.8V = 255

So
a 1.5V readadc input with a supply of 5V = 1.5/5*255 gives a readadc = 76(.5)
and
a 1.5V readadc input with a supply of 2.8V = 1.5/2.8*255 gives a readadc = 136(.6)
 
Last edited:

lbenson

Senior Member
Lowering the supply voltage reduces battery drain, but I think that in this context, "underclocking" refers to reducing the clock speed of the PICAXE at a given supply voltage (which also reduces battery drain). See, for example, this thread for saving battery power: http://www.picaxeforum.co.uk/showthread.php?t=8353

It references other threads in which the issues are addressed. The consensus seems to be that before you do an ADC, you should resume full speed, and then resume the underclocked speed afterwards.

If I am mistaken in your intention, pardon.
 

lbenson

Senior Member
Non X1/X2 chips can poke the OSCCON register (e.g., "poke $8f,%00000000") to run at various speeds down to 31.250kHz. This might not be considered a "standard" picaxe basic command. Search on OSCCON.
 

westaust55

Moderator
True lbenson.

Protolisk would need to look at the datasheet from the microchip website for the PIC12F683 (upon which the 08M is based).
Have a look at datasheet page 20.

So as not to disturb other functions/flags the best method may be code along these lines:

Code:
PEEK $8F, b0       ; fetch the current OSCCON value
b0 = b0 AND $0F ;  this retains the lowest 4 bits
b0 = b0 OR [B][COLOR="DarkRed"]$xx[/COLOR][/B] ; to merge in the new speed factor/bits
POKE $8F, b0
Where $xx = $60 for 4MHz, $30 for 0.5MHz, $20 for 250kHz and $0 for 31kHz.
See the datasheet for other values.

If OSCCON bits 1 and 2 are 0 this suggests the HF and LF internal oscillators are unstable - may (?) result in unwanted operation.
 
Last edited:

tiscando

Senior Member
Oscillators inside the picaxe

If OSCCON bits 1 and 2 are 0 this suggests the HF and LF internal oscillators are unstable - may (?) result in unwanted operation.
I found out on the datasheets for the picaxe 28x1, that (almost) every PIC used by picaxe has a
-LFintosc, which is 31-32kHz and unstable, and is used for the watchdog timer and other background supporting perhiperals inside the chip, possibly including the brown-out detector.
-HFintosc, which is almost accurate, is 8MHz, and is used for the high-speed timing perhiperals including the PWM. This oscillator is turned off when not used, e.g. after the overall clock speed is set to use the LFintosc (k31), after the 'end' command is executed, or during the 'nap' or 'sleep' commands.

The osccon register controls the switch with all signals fed in from the stages of the HFintosc's frequency divider, or counter, and the LFintosc. The multiplexer's default setting is being closed on the /2 line from the frequency divider (4MHz). At the lowest setting (31kHz), the switch is closed on the LFintosc signal. The switch's output is fed into the processor and perhiperals e.g. the PWM.
The frequency divider divides the HFintosc's output signal (8MHz) down to 125kHz, with 4MHz, 2MHz etc. outputs also, and the switch selects which signal (frequency), including the LFintosc's, to feed into the rest of the PIC(axe).

This is some more info to add to the forum (unless someone else stated this).;)
 

BCJKiwi

Senior Member
In the absence of any response from Protolisk so far, just want to clarify what I figured was the intitial question - i.e. it is all about voltage levels and readadc!
The use of the term underclocking I took to be incorrectly used and was intended to refer to 'undervoltage', or running on reduced voltage and its affect (or otherwise) on readadc.

However, useful insights on the unrelated speed issues.

Come in Protolisk - have we answered the initial question yet?
 
Last edited:

Protolisk

Member
Well sort of. BUt all I really want to know is does under clocking it or making the picaxe use lower voltage. Will that give me the same readadc value whether or not my batteries are brand new or low?

Some extra questions would be
If I'm reading adc and the source voltage for the picaxe is say 3v but the pot voltage is 7v. At the maximum setting of the pot what will the readadc value scale to fit 0v-7v or would there be some kind of deadzone?

Thanks for the help so far.:):)
 

westaust55

Moderator
Well sort of. BUt all I really want to know is does under clocking it or making the picaxe use lower voltage. Will that give me the same readadc value whether or not my batteries are brand new or low?

Some extra questions would be
If I'm reading adc and the source voltage for the picaxe is say 3v but the pot voltage is 7v. At the maximum setting of the pot what will the readadc value scale to fit 0v-7v or would there be some kind of deadzone?

Thanks for the help so far.:):)
Underclocking does not automatically cause the PICAXE to operate at a lower voltage. You can operate at a lower voltage even at full speed as per the PIC datsheets.
Either or both reduced voltage and/or frequency will reduce power consumption for the PICAXE chip.

Your analogue value from the Pot should not exceed the PICAXE supply voltage. If you want to measure the range 0 to 7 Volts then use a potential divider constructed form two resistors so that at 7V the PICAXE only sees the 3.0V (same as the PICAXE).
Calculating and installting one resistor on the positive side of the Pot will achieve this. Then you can scale the READADC result to match the range 0 to 7Volt.
 

BCJKiwi

Senior Member
Underclocking (speed) is unrelated to the voltage.

i.e. you can't use clock speed to offset the falling voltage to maintain the readadc value if that is what you are asking.

If you require that level of accuracy then you need an external reference voltage to compare with the voltage being measured so the changing ADC value with falling supply voltage can be compensated for.

There are a number of threads on this precise topic.
 

Protolisk

Member
So will it give me the same readadc value running at lower voltage. As long as I keep that voltage the same. Using a voltage regulator or something similiar. I would also have to use a potential divider to lower the voltage from the pot so that its equal to the picaxes.

Thanks Westaust55

Then I would have to constantly replace the external power source.
 

premelec

Senior Member
The READADC value is ratiometric to the voltage ON THE PICAXE power pin - if that varies the ADC reading with the same input voltage will be different proportional to the variation.
 

BCJKiwi

Senior Member
Protolisk,

go back to my post #2
If the Picaxe supply is fixed, measure that voltage at the supply pin on the picaxe chip with everything running. Then do the math to sort out the readadc values for the READADC voltage(s) you are interested in as per post #2.

If you are looking for higher resolution, use readadc10 instead of readadc (provided the AXE you are using supports it which is any current AXE!).
 

westaust55

Moderator
Protolisk,

How about a circuit of what you are trying to achieve.

The voltage you are trying to measure has varies from 1,5V at post 1:
For example I want to read the voltage of a 1.5v pot(not sure how many ohms it is).
If I run the picaxe normally then the readadc value of the pot will change depending on the level of my batteries. If I under clock the PICAXE will I get the same value even if my batteries are low or fully charged?
to 7V at post 9:
If I'm reading adc and the source voltage for the picaxe is say 3v but the pot voltage is 7v. At the maximum setting of the pot what will the readadc value scale to fit 0v-7v or would there be some kind of deadzone?
Its like trying to hit a moving target.
 

BCJKiwi

Senior Member
@Westy,
YIKES!!! - missed that one - good catch!

Readadc voltage at the AXE cannot exceed the supply voltage and still be meaningful or safe.

If monitoring a POT, then the MAXIMUM value possible under any condition from the pot must be scaled (voltage divider?) to <= the MINIMUM supply voltage.

Then do the math at the the normal working supply voltage.
 

Dippy

Moderator
Westy has obviously bought the Turbo Crystal Ball from Ebay :)

I hope proto has got the idea now. He had me worried ;)

1. Changing the 'clock speed' will not (arguably) affect the ADC.
2. The number you get from a READADC command is basically a ratio of the 'sample' voltage compared to the PICAXE supply voltage.
3. If the PICAXE supply voltage changes AND the 'sample' voltage changes then you'll get a mess.
4. If (3) above then you will need a reference. Then you can 'calibrate' against it using a second ADC read.
5. Easier to use a voltage regulator if pacticable. But be aware of droop as batteries die. Check regulator 'drop out'.
6. The ADC 'sample' voltage should NOT be higher than PICAXE supply voltage.
7. If (6) above then use a potential divider so that the Maximum ADC 'sample' voltage < PICAXE supply voltage.
Calculating the values for a simple 2-res pot div is easy.

If You have :

Sample V
|
|
Res 1
|
----------- PICAXE ADC pin
|
|
Res 2
|
|
Gnd

Then:
Voltage to ADC pin = (SampleV x Res2) / (Res1 + Res2)

You can then easily rearrange if needed. Ideally Res1 < 10K-15K but not too low.

Ques to more experienced PICAXErs: can you POKE to access the Vref pins to use an external rereference?
 

Protolisk

Member
Hey thanks for the help. Dippy summed it up pretty well.

The 7v question was just hypothetical.

Seems like the best way is to use a voltage regulator. Pitty I can't find any cheap ones close to around 3v. Only found a 5v. An adjustable is only .50c more which says (+- sign) 2-37v. That should be able to give me about 3 right?
 

Protolisk

Member
Nice thanks westaust.

Whats the difference between the CZ 3v and the one without CZ on the end.
LP2950CZ 3V 100mA Low Drop-out Regulator
LP2950 3V 100mA Low Drop-out Regulator
 

Dippy

Moderator
Top