Long Term Astable and Monostable Multivibrators - PICAXE-08

copyright, Peter H. Anderson, Elmore, VT, July, '04


Introduction

(Note that although these routines were tested on a PICAXE-08, the general discussion relates to all members of the PICAXE family.)

At least once a week, I read on various news groups of someone who desires to implement a design involving relatively long time periods. For example, to perform a two minute task every hour or if there is a trigger event to operate a lamp for ten minutes.

The responses usually tend toward a 555 timer, with details of using a low leakage CMOS 555, very large resistors and very large, low leakage and presumably very accurate capacitors and a very quiet power supply. The bottom line is that times of over ten seconds using a 555 are really impractical. Indeed, one might design a 58 minute timer using a 555 on paper, but I sure wouldn't place bets on its reliability and repeatability. It may be ten minutes one time and 50 the next and if this meets the 58 minute "spec", fine.

Another approach which is often offered is a crystal oscillator with a good long countdown chain. Designing the divide by 60 and the divide by 58 stages are excellent design problems for electrical engineering students, but once done, it really serves little purpose in today's world of processors.

The PICAXE is in my mind the ideal, at least for limited quantities. Programming a PIC might be better approach if your development time is of no value, you are looking for experience in developing a PIC program or you are fielding hundreds of devices.

Program Astable1.Bas

In the following, ASTABLE1.Bas illustrates a design where a lamp (or similar) is turned off for 58 minutes and then turned on for two minutes. This is continually repeated.

Note that in addition to the lamp (using a solid state relay or similar) on Pin2, a test LED is also provided on Pin1 which might be used to verify the design is operating and to also adjust the timing. In the inner loop, the LED is turned on for 500 ms and turned off for 500 ms. However, the pause is not precise, there is additional overhead associated with the for-next loops and the internal PIC oscillator is not exactly 4.0 MHz. Using a wall clock with a second hand you may wish to count the number of LED flashes over a period of five minutes and adjust the pause time. For example, if you count 270 flashes (ten percent low), you might adjust the pause time to 450 ms. Once "calibrated", the time will be stable so long as the ambient temperature does not vary drastically.

This design might be easily reworked to turn on a lamp at 8:00 PM and turn it off at 11:00 PM. However, recognize that the accuracy is not such that the design can be fielded for a month and expect that the lamp will still turn on at 8:00. However, the accuracy and simplicity is several orders of magnitude over anything using a 555 clock.

' Astable1.Bas - PICAXE 08
'
' 58 minutes off, 2 minutes on.
'
' Turns lamp on Pin2 on for two minutes each hour.
' Test LED on Pin1 for verification the design is operating
' and for time calibration.
'
' Uses 65 of 128 bytes
'
' copyright, Peter H Anderson, Elmore, VT,  July , '04

   Symbol Mi = B0
   Symbol Se = B1

TOP:
   Dir2 = 1	' make Pins 2 and 1 outputs
   Dir1 = 1

   Pin2 = 0     ' turn off lamp - off or 58 minutes
   For Mi = 1 to 58 ' minutes
     For Se = 1 to 60 ' seconds
        Pin1 = 1; ' test LED
        Pause 500
        Pin1 = 0
        Pause 500
     Next
   Next

   Pin2 = 1	' turn lamp on - on for 2 minutes

   For Mi = 1 to 2 ' minutes
     For Se = 1 to 60 ' seconds
        Pin1 = 1;
        Pause 500
        Pin1 = 0
        Pause 500
     Next
   Next

   GoTo TOP

Program Mono1.Bas

This program illustrates a long term monostable multivibrator. When an input on Pin3 goes low for more than one second, a lamp on Pin2 (using a solid state relay or similar) is operated for ten minutes.

As with Astable1.Bas, a test LED is provided on Pin1 to provided a visual indication that the circuit is running and for calibration.


' Mono1.Bas - PICAXE 08
'
' If Input in Pin3 (term 4) goes low for more than one second then processor
' turns on a lamp for ten minutes.
'
' Uses 59 of 128 bytes.
'
' copyright, Peter H Anderson, Elmore, VT,  July , '04

   Symbol Mi = B0
   Symbol Se = B1
   Symbol N = B2


Top:
   Dir1 = 1	' make Pin1 and Pin2 outputs
   Dir2 = 1
   Pin1 = 0 ' test LED off
   Pin2 = 0 ' lamp off

   If Pin3 <> 0 Then Top
   ' else, it is zero
   For N = 1 to 100
      If Pin3 <> 0 Then Top
      ' else, it still is zero
      Pause 10	' 100 * 10 ms = 1000 ms = 1 second
   Next


   Pin2 = 1     ' turn on lamp for
   For Mi = 1 to 10 ' minutes
     For Se = 1 to 60 ' seconds
        Pin1 = 1; ' test LED
        Pause 500
        Pin1 = 0
        Pause 500
     Next
   Next

   Goto Top