Underclocking a 28X2 - is this correct?

Mikler

Member
(Yes - I have done a search for 'underclocking' :)

Help appreciated as I am very new to all this....

I am trying to 'underclock' a 28X2, just before 'sleep'
and 'back to normal' i.e. 8Mhz internal immediately after 'sleep

Is the following code correct for a 28X2?

pokesfr $D3,%00000000 ' = slow down to 31Khz
sleep 1
pokesfr $D3,%01100000 ' = 8 MHz; speed back up

If the above is OK, then I have another question - my software uses an interrupt - is it possible for the interrupt to take place before it has reverted back to full speed? If yes, is the solution to temporarily disable the interrupt?

Thanks very much!

Mik

Mik
 

eclectic

Moderator
Curiouser and curiouser?

I've just tried Mik's program
Code:
#picaxe 28x2 ; 3volt

high C.0, C.1, C.2, C.3, C.4, C.5, C.6, C.7
high B.0, B.1, B.2, B.3, B.4, B.5, B.6, B.7
disablebod

main:

disablebod
sleep 4
SOUND B.7,(80,10) 'give me a bleep
low C.0 'flash test LED
pause 2000;0 'pause to display LED
high C.0 'switch off LED
goto main 'loop
Axe28x2 3v, in anAXE022 board, with two resonators.
Loaded the program, with jumpers still in place.

Around 0.002 mA (~2uA)
~4mA when c.0 on, then back to ~2uA

However,

removing the jumpers or loading the program without jumpers
results in ~620 mA (similar to Mik's results).

Replacing the jumpers, (either 4 or 16MHz)
and back to ~2uA

Test repeated with two different 28X2 and two different AXE022

Hmm?


PS Mik ; see manual 2, p.183 Setfreq

PS2 Adding Setfreq m8 also made no difference
 

Attachments

Mikler

Member
hmmm...

Note that I am not using an external resonator?

I assume that by having a resonator in the circuit, it stops the input pin floating....?

Fascinating how close our figures are....
 

hippy

Ex-Staff (retired)
The recommended way of updating any SFR would be to load it and only change the bits which need to be changed. So to clear bits 4,5,6 in OSCCON to select 31kHz ...

PeekSfr $D3, b0
bit4 = 0
bit5 = 0
bit6 = 0
PokeSfr $D3, b0

Of course the bit twiddling can be done with AND and OR and a simple POKESFR of a constant value can be used when all bits need to be set ( BitX=Y ... PokeSfr $ZZ,b0 is still a useful trick ).

Your POKESFR $D3,%00000000 looks okay but I haven't investigated what the IDLEN and SCS<1:0> bits should ideally be. You may also need to adjust OSCTUNE ( INTSRC, PLLEN ).

To restore speed it's probably best to save the contents of whatever SFR are before being updated and set them back the same when done.

Yes, an interrupt could take place before full speed is restored and the easiest thing is to disable interrupts and enable them after restoring the speed.
 

Mikler

Member
Hippy

Can I simply reverse use the same code to set the speed back to 8Mhz? i.e.

PeekSfr $D3, b0
bit4 = 0
bit5 = 1
bit6 = 1
PokeSfr $D3, b0

Is that what you are saying?

And thanks re interrupt help!

Mik
 

hippy

Ex-Staff (retired)
removing the jumpers or loading the program without jumpers results in ~620 mA (similar to Mik's results).

Replacing the jumpers, (either 4 or 16MHz) and back to ~2uA
That would seem to fit with having the OSCIN pin connected or not. When connected ( to resonator or tied to 0V ) everything is stable, when floating the oscillator block, PLL, startup timer, failsafe clock monitor and everything else related are probably actively trying to make sense of the fluctuating input and drawing current while doing so.

I think you meant 620uA not mA. That overhead probably exists while an external resonantor isn't connected and the pins are left floating ( probably on all X1's and X2's ) but shouldn't adversely affect actual operation of the chips other than being an overhead which will likely not be significant in most PICAXE projects we see in the forums.
 

hippy

Ex-Staff (retired)
Can I simply reverse use the same code to set the speed back to 8Mhz?
Probably, though if the actions of altering the bits alter other bits ( I haven't studied the data sheets ) they won't get changed back. One way is not to re-PEEKSFR a second time ...

PeekSfr $D3, b0
bit4 = 0
bit5 = 0
bit6 = 0
PokeSfr $D3, b0
Sleep
bit4 = 0
bit5 = 1
bit6 = 1
PokeSfr $D3, b0
 

eclectic

Moderator
That would seem to fit with having the OSCIN pin connected or not. When connected ( to resonator or tied to 0V ) everything is stable, when floating the oscillator block, PLL, startup timer, failsafe clock monitor and everything else related are probably actively trying to make sense of the fluctuating input and drawing current while doing so.

I think you meant 620uA not mA. That overhead probably exists while an external resonantor isn't connected and the pins are left floating ( probably on all X1's and X2's ) but shouldn't adversely affect actual operation of the chips other than being an overhead which will likely not be significant in most PICAXE projects we see in the forums.
Thank you for the correction. :)

Post now edited.
e
 

Mikler

Member
Hmm...

I have slowed the speed down from 8Mhz to 31Khz but it has made absolutely no difference to the current consumption. (As this is anyway 3uA, I am happy and can live with it)

I am sure that my code is working as I tried reducing it down to just 1Mhz and my delays are far longer and my audio (piezo sounder) is also lower....

Very puzzled..... something is not right....
 

eclectic

Moderator
Hmm...

I have slowed the speed down from 8Mhz to 31Khz but it has made absolutely no difference to the current consumption. (As this is anyway 3uA, I am happy and can live with it)

I am sure that my code is working as I tried reducing it down to just 1Mhz and my delays are far longer and my audio (piezo sounder) is also lower....

Very puzzled..... something is not right....
I've just tried

Code:
#picaxe 28x2

pwmout c.1,99,200
pause 5000
setfreq k250
stop
Then watched the results on a 'scope.
Works fine on k values 500 and 250, but,

resets on k31, after about two seconds

e
 
Last edited:

Mycroft2152

Senior Member
E,

Interesting thread.

In post#2 you have a photo of your AXE022 board. I don't have an Axe022.

The schematic on the data sheet shows a crystal and a pair of caps, and also a resonator. Your photo is missing the caps. Are you using 2 resonators?

Also what exactly do the jumpers do.

Can ypou put together a table of current consumption of internal and external resonators versus clock frequency?

Myc
 

eclectic

Moderator
E,

Interesting thread.

In post#2 you have a photo of your AXE022 board. I don't have an Axe022.

The schematic on the data sheet shows a crystal and a pair of caps, and also a resonator. Your photo is missing the caps. Are you using 2 resonators?
Yes 4MHz and 16 MHz

Also what exactly do the jumpers do.
connect the resonators

Can ypou put together a table of current consumption of internal and external resonators versus clock frequency?
basically it's 0.002 mA (2micro-Amps) as the lowest so far
Myc
Hope this helps.
e
 

BCJKiwi

Senior Member
@ Myc

Did some tests on a 28X1 at #setfreq m8
Connecting oscin (Leg9) to 0V made no change in current.
Connecting oscin to 0V via 4k7 or 10k actually increased the current by 0.01mA

So this issue appears to be an X2 issue only.
 

Technical

Technical Support
Staff member
The PIC oscillator selection is set by a 'configuration fuse' which is fixed at firmware programming time and therefore cannot be changed. For maximum flexibility and choice of operating speeds the 28X2/40X2 parts are programmed to use a primary external oscillator and secondary internal resonator. Under normal program operation this basically means the PICAXE firmware can use either internal or external resonator at will - changed by the setfreq command

When the PIC goes into sleep mode it stops the oscillators completely to reduce power consumption. But when using fuse settings like this the PIC does actually expect there to be a resonator/crystal present, and so the sleep 'internal PIC hardware setting' is based upon an assumption that it is stopping a resonator. In the PICAXE scenario where the resonator may have been completely omitted this can lead to noise causing an increased current consumption.

So,
a) if not using sleep/doze (and only want to work with internal resonator) the external resonator connection pins are not that relevant
b) if using sleep and concerned about reducing current as much as possible don't let the resonator pins float. Obviously the best way to do this is to connect a resonator/crystal (as most users will do anyway!), but a high value resistor won't cause any damage either.
 
Last edited:

eclectic

Moderator
To Tech.

What happens with k31?

I have not the slightest use for the command, but,
someone might.

e
 
Last edited:

Mikler

Member
Hi BCJ

>> Connecting oscin (Leg9) to 0V made no change in current.

Have you tried it via a 100K resistor (in case this makes a difference)

Rgds

Mik
 

BCJKiwi

Senior Member
No, did not try it with 100k but did try it with 4k7 and 10k as stated - they both increased the current so I would expect 100k to increase the current even further as it would lift the port even higher from 0V - besides, 100k is well above the nominal impedence for the port as recommneded by Microchip.
 
Last edited:

tchapin

New Member
SETFREQ command does not affect SLEEP command, it uses internal timer.

My tests with the 28X1 and 28X2 indicate that the PAUSE power consumption is >10x more than SLEEP power consumption at k31. At higher clock speeds the difference is even greater 50-250x more power in PAUSE than SLEEP.

NAP isn't supported on the 28X2 so it's very difficult to get a sub 2.1 second (sleep timer resolution) low power delay.

k31 and k125 commands don't work on 28X2, hopefully will be fixed in next compiler revision.
 
Top