28x2 and sleep

martinn

Member
I have been playing with the axe401 28x2 shield, I am trying to create a low power use datalogger and the 28x2 hardware interrupt is brilliant. I have been try to have the 28x2 sleep until an interrupt or the minutes (for each hour) reaches 59 minutes, the interrupt works fine, but sleep is not very accurate, I current wake the unit at least 5 minutes before the 59th minute otherwise it misses it many times. Would an external resonator improve the accuracy of sleep?

Martin
 

papaof2

Senior Member
Accurate time keeping will require a real time clock (RTC). The DS1307 is the most common chip, with a complete RTC board available from futurlec for about $8US http://futurlec.com/Mini_DS1307.shtml

The PICAXE could be run at low speed (31KHz) and it could count the 1 second pulses from the RTC to determine when close to the correct time. The PICAXE would then go to full speed so it can read the RTC via I2C and get the exact time.

John
 

srnet

Senior Member
If you are wanting to put the 28X2 to sleep and wake it up sometime later, accuratly, then its and idea to choose a RTC with an interrupt output such as the DS1339.

You could then also turn off the power to your datalogger completly, and use the alarm interrupt to turn the power back on again.

The DS1339 RTC is one of the few (maybe the only) of the small 8pin RTCs that will charge a small lithium battery.
 

martinn

Member
I should have said I am using a RTC1307 with the Axe 410 shield to get the time. I like the idea of counting the pulses, I can try that straight away. Also I see with the alarm RTCs, that the alarms can be set to repeat on XX minutes, so the RTC can interrupt wake the 28x2 each hour and sleep the rest, now I just need to setup enough eeprom memory to last a year.

Thanks
Martin
 

westaust55

Moderator
More detailed answer from PICAXE Manual 2:
Some further explanation for the accuracy of the sleep command:
The watchdog timer (WDT) always derives its timing from the fixed (approx 31 kHz) internal RC oscillator block (INTRC).
Selecting other clock sources internal or external for the main processing functions does not alter the WDT clock.
 

srnet

Senior Member
Also I see with the alarm RTCs, that the alarms can be set to repeat on XX minutes, so the RTC can interrupt wake the 28x2 each hour and sleep the rest
Some do.

RTCs vary quite a bit in capability. Some have (small amounts) of battery RAM and EEPROM, some have time stamps for battery fail, some have battery backup options etc ......

A repeating hourly\daily alarm is easy on the code, but you can emulate this with any of the RTCs that have an alarm function.
 

srnet

Senior Member
Also I see with the alarm RTCs, that the alarms can be set to repeat on XX minutes, so the RTC can interrupt wake the 28x2 each hour and sleep the rest
Some do.

RTCs vary quite a bit in capability. Some have (small amounts) of battery RAM and EEPROM, some have time stamps for battery fail, some have battery backup options etc ......

A repeating hourly\daily alarm is easy on the code, but you can emulate this with any of the RTCs that have an alarm function.
 

srnet

Senior Member
The WDT gets its timing from the LFINTOSC source.

INTOSC is the multiplexer that provides the internal clock to the CPU and the like, and takes as its inputs the output of the HFINTOSC, MFINTOSC and LFINTOSC circuits (on a 18F25K22\28X2)
 

srnet

Senior Member
I have been doing some sleep tests on a 28X2 today.

My 28X2 with all pins set to output and nothing else connected apart from a resistor pullup on the reset pin and one of the resonator pins (9) grounded consumes 19uA in sleep and 27uA running in a loop at setfreq k31. Leave the resonator pin floating and current consumprion rose by some 300uA.

In the same conditions a native 18F25K22 consumes 11uA in sleep, with no watchdog running. This is in line with data sheets specs. Of note is that the LF version of the 18F25K22 has a quoted sleep current of 20nA.

So unless you need to be really miserly with power there is not a lot to be gained with 1 28x2 using sleep versus polling an alarrm pin on a RTC.
 

westaust55

Moderator
The WDT gets its timing from the LFINTOSC source.

INTOSC is the multiplexer that provides the internal clock to the CPU and the like, and takes as its inputs the output of the HFINTOSC, MFINTOSC and LFINTOSC circuits (on a 18F25K22\28X2)
Looking at the datasheet for the newer 28X2 (PIC18FK2522) versus the earlier 5V only 28X2 (PIC18F2520) which I had considered previously, there seems to be a considerable difference in the options for the Watchdog Timer (WDT) clock source including now a postscaler function.
So in conclusion we need to know which version of a PICAXE/PIC chip is being used rather than assuming ( and we know what that can lead to . . . . .)
 

martinn

Member
I am logging the number of times a reed-switch is triggered (via interrupt), these counts are summarised hourly and sent to eeproms (I am also playing with logging to a sdcard). It would be nice to get a year out of the unit. The unit can run at <500kHz when woken up to record the read switch and go back to sleep, probably best at 1-2mHz for writing to the eeprom. I have assumed a per day of 200 wakes for 15 secs and 24 wakes of one minute (these are over estimates) at 5mA, and the rest sleep at 0.02mA, giving 6.6mAh/day, so out of a reasonable set of alkaline batteries (2700 mAh) I should get 400 plus days.

The 28x2 is one of the new multi-voltage versions. And fitted to the Axe401 shield.

Martin
 

srnet

Senior Member
20uA might be a reasonable planning figure for a 28X2 in perfect conditions (i.e nothing connected to it) but as soon as you start adding external circuits to the pins you introduce the possibility of additional power drain.

A good plan is to start with a naked 28X2, nothing connected apart from the programming circuit, set all the available pins to output and low, measure the sleep 0 current and build up from there.

Once a circuit is built and complete , especially if its on a PCB, if the sleep current is higher than expected, you will have problems working out why.
 
Top