Using Picaxe to monitor timing sequences

mlaymance

New Member
I am working on a project that requires basically 5 timers.

It is for the clocking of a sequencer. The sequencer basically works like this:

There are 5 sets of contacts on the sequencer that open and close at different time intervals.

Applying the appropriate voltage to the sequencer starts a timer. After 1-30 seconds a set of contacts close, then another, then another...etc.
The way that contacts close is by a Thermal heater that heats a thermal disk conected to the contacts. The conatcts are "GANGED" together, and the sequencer is built by choosing different time rated contacts at the time of assembly.

I would like to use a Picaxe controller as a base for the tester that checks these devices for proper operation.

My requirements would be that it monitor 5 sets of contacts, Provide an output to control a power relay (through a transistor or driver) to turn on the power (24VAC), and provide the timing of these units to either a computer screen or an LCD display.

Can someone recommend a Picaxe controller that would work for this application? Also any other information/Advice would be welcomed.
 

inglewoodpete

Senior Member
You are probably a little 'underwhealmed' by the responses to date :) Chances are no-one has built something similar, so haven't offered a solution.

On it's own the PICAXE is not an accurate timer. How accurate do you need the 1-30 second time periods measured (1 Second, 1 mS, 1uS?). Getting the PICAXE to determine the time of 5 timers at once can be a challenge. You will almost certainly need additional hardware if the result needs to be accurate.
 

BeanieBots

Moderator
I'm gussing that the fact that the contacts are timed by a thermal system means that the timing is not very accurate.
If this is true, then it should be possible to do very easily with a basic software timed loop.
In your other thread, you say you have a 20M. That could do it.

What do you need to display?
A very simple & cheap 2X16 LCD display would be the AXE033.

Wait for an input to trigger the start.
Then enter a loop with a known delay which increments a counter.
Each time around the loop, test for closure of the first set of contacts.
If the contacts are not closed, test the counter, if it is greater than X, then it took too long or never happened. If it's less than Y, then it was too quick.

Do that for each of the five contacts.
If you need to diplay the actual time for each contact then it's a little more complex but the principle is the same.
 

hippy

Technical Support
Staff member
Can someone recommend a Picaxe controller that would work for this application?
You appear to need 5 inputs plus two outputs ( power control and serial to LCD / PC ), so a PICAXE-14M, 18M or 20M should be able to do the job if the program isn't complicated. If you need a more complicated program then a PICAXE-18X or 28X1 as they have larger memory capacity.

I don't have any notion of how complex the program would be so I'd start with an 18X, or a 28X1 if I thought it may become necessary to add additional inputs later ( cancel, restart buttons etc ). After prototyping the code can be changed for use with a smaller PICAXE.

You could start by assuming an 18X or 28X1, write the bulk of the code, simulate to check correctness then see how much memory is used which will give an idea of what you need before buying any hardware. As a rule of thumb, the 14M, 18M and 20M can have around 80 lines of simple Basic commands, the 18X and 28X1 around 600.
 

mlaymance

New Member
The clock accuracy would have to be somewhere in the range of +/-1/2 second.

This being said, I assume that I would have to use one of the picaxes that have a built in clock for accuracy?

My Idea was to use 1 input as a start/reset, and one input for each of the contacts that were monitored.

The output preferably would go to an LCD display that would display the start time of the contact closure (I.E. 1 sec, 2 sec.... etc) and duration of the closure (10 seconds, 20 sec...... etc).

This would provide me with enough information to determine of the devices were good or bad.

The other scenario would be compare the values captured to a chart that would determine pass or fail Via display or LED indicator.

I would not want to overwork the processor so am flexible in the output indications.

Thanks,
Opinions/Suggestions?
 

BeanieBots

Moderator
Actually, the externally clocked chips are more accurate.
Internal clocks are about 3% which is just outside what you want.

Consider the 28X1 with an external resonator.
Then consider code like this:-
Code:
Do while trigger=false 'wait for start signal
Loop

Counter = 0

Do while Output_1=false
   Counter=Counter+1
   If counter > Max_Value then Error_handler
Loop

If Counter < Min_Value then Error_handler

..and so on for each output to be tested
The AXE033 has two lines with 16 characters on each line.
That should be enough to give fairly comprehensive information but a simple LED (as well?) could easily give pass/fail indication.
 

womai

Senior Member
I'd recommend the AXE033 for display, because it has a Dallas Semi real-time clock chip as an option (needs to ordered separately). Then determining the exact time becomes quite simple.

- Picaxe reads the start time from the real time clock.

- The Picaxe just runs in a fast loop (repeats several times per second), looking at whether one of the contacts has just closed. To do this, store the last contact position (open or closed) for each contact, and compare with the current position.

- If it has changed, get the time from the real time clock and print the difference between the current time and the start time

- Then the current switch positions are stored as "previous position", and the loop repeats.


Alternatively you can use the Dallas Semi real-time clock chip on its own as well (needs a suitable crystal) and send the data to a PC using sertxd. For a start, the results can be logged on any terminal program, e.g. the one built into the Programming Editor.

Another option would be to use the internal timer for timekeeping (You will need an 28X1 or 40X1 chip for that). Not as precise as the real-time clock chip, but 1sec accuracy should be possible to achieve. Accuracy is determined by the clock source; at the very least use a ceramic resonator (accurate to typically better than 0.5% in my experience, but could be as large as 1%).

Wolfgang
 
Last edited:

lbenson

Senior Member
Don&#8217;t pay too much attention to what I post here&#8212;I have no professional credentials and am just playing. I have made a lot of assumptions. Among them, that you don&#8217;t need to know the real time, just the time elapsed since the sequence began. I have used a 14M. The schematic assumes that you can get the contact information to the picaxe at a voltage level no greater than the supply voltage. Also that you can do whatever transformation is necessary to get a picaxe output to turn on your 24-volt supply.

The program looks for a pushbutton input to the picaxe to be pressed +and+ released. When this is done, the program cycles through a loop, the timing of which is controlled for the most part by the &#8220;pause 250&#8221; at the end, which makes each loop take about a quarter of a second and assumes that the time the instructions take within the loop are negligible (this should satisfy your +/- 1/2 second requirement). The program assumes that the contacts all start in the &#8220;off&#8221; position. The present condition of the contacts are read with &#8220;inputs = pins&#8221;, reading the 5 standard inputs of the 14M. The program loops 5 times, once for each contact, and determines if there has been a change in the status of the contact, either from on to off or from off to on. It prints a message using sertxd giving the contact number, whether it went on (signified by &#8220;+&#8221;) or off (&#8220;-&#8220;). It also gives the time in seconds and 25-hundredths of a second when the event occurred.

This will run in the simulator. Remember to turn the pushbutton on and off (C0). Then turn on and off inputs 0-4 as you wish.

Code:
#PICAXE 14M

symbol contactMovement = b12 ' "+"=on; "-"=off
symbol seconds = b11    ' number of seconds since start of sequence
symbol hundredths = b10 ' remainder hundredths of seconds since start
symbol bitposition = b6 ' bit-position of contact
symbol contact = b5     ' which contact are we working on
symbol newvalue = b4
symbol oldvalue = b3
symbol lastinputs = b2  ' what the last settings were
symbol loopcount = b1   ' about a quarter of a second
symbol inputs = b0      ' either C port or normal inputs

dirsc = %00000110 ' c port has C0 as input
main:
  do
    do                   ' wait while switch off
      if portc pin0 = 1 then: exit: endif
      pause 100
    loop
    do                   ' wait until switch is released
      if portc pin0 = 0 then: exit: endif
      pause 100
    loop
  ' this begins a timing cycle of about a quarter second
    loopcount = 0
    high 1              ' turn on the 24-volt supply
    do
      inputs = pins   ' get the settings of the contacts
      if inputs <> lastinputs then ' we have a change
        bitposition = 1          ' start with contact 1
        for contact = 1 to 5       ' test the 5 contacts
          newvalue = inputs & bitposition ' non-zero if contact is now on
          oldvalue = lastinputs & bitposition ' non-zero if contact was on
          if newvalue <> oldvalue then
            if newvalue > 0 then ' contact just turned on
              contactMovement = "+"
            else
              contactMovement = "-" ' contact just turned off
            endif
            seconds = loopcount / 4  ' # seconds since start of cycle
            hundredths = loopcount // 4 * 25 ' hundredths of seconds
            sertxd ("Contact ",#contact," went ",contactMovement," at ",#seconds,".",#hundredths," seconds",cr,lf)
          endif
          bitposition = bitposition + bitposition ' shift left
        next contact
        lastinputs = inputs
      endif
      inc loopcount
      pause 250
    loop until loopcount >= 250 ' 250 quarter seconds would be 1+ minutes
    low 1            ' turn off the 24-volt supply
  loop
Sample output looks like: "Contact 3 went + at 4.75 seconds&#8221;. The loop only runs for 250 iterations--about a minute. If you want it to be longer, make loopcounter a word variable and change the loop exit criteria--that should give you plenty of time.

Dippy might say that some people have too much time on their hands.
 

Attachments

Last edited:

mlaymance

New Member
WOW!!!

Very nice information. I will be ordering the components this week for this as shown. Thanks greatly for the information. I will have to change the routine a bit since some of the contacts can stay closed for up to 110 seconds.

You guys are great!

Thanks,
Michael
 

lbenson

Senior Member
Glad you found it helpful. I realized that I forgot to turn on and off the 24-volt supply. "high 1" after the pushbutton release is detected will turn it on. "low 1" will turn it off when the routine times out or at a point that you determine. I've gone back and put those in.
 

mlaymance

New Member
Ibenson,
Thanks a bunch for your help.
I have already used the 20M chips for other projects, but may order more for this one. They seem to work well for a basic chip if you don't need all of the bells and whistles and can get by with the 256 byte memory.

Just a general question.... would it be very hard to pipe this information to the netserver module?
 

lbenson

Senior Member
I haven't used the netserver--have used the SimpleLan instead, and very much like the ability to see outputs with a browser. But I don't think you have enough program space with the "M" class of picaxe to do much of anything. Any bells and wistles require an 18X--for SimpleLan, a 28X1 is required to catch responses with hserin (tho I think some have succeeded with serin, perhaps by running at a higher speed). I do wish there were a 14X or 14X1, but I think we're still waiting for Microchip to produce the underlying chip--and then for RevEd to decide that it fits in their business model.
 
Last edited:

lbenson

Senior Member
The time the program takes to execute instructions within the loop becomes less negligable as the total time increases. The times when a contact changes might be pretty close to negligable, but the times when there is no change would add up. Consider the instructions executed when there is no change:

Code:
    do
      inputs = pins   ' get the settings of the contacts
      if inputs <> lastinputs then ' we have a change
        ... 
      endif
      inc loopcount
      pause 250
    loop until loopcount >= 250 ' 250 quarter seconds would be 1+ minutes
BeanieBots gave timing measurements (subject to caveats) in this thread: http://www.picaxeforum.co.uk/showthread.php?t=1128&highlight=commands
Code:
if       880 microseconds
=        1000 microseconds
+        1000 microseconds
pause    1450 microseconds
A rough guess might be about 7 milliseconds per loop (exclusive of the pause time) when there is no change. Over the course of two minutes this would be 2minutes*60seconds*4loops_per_second*7milliseconds or 3360 milliseconds over 2 minutes--a bit more than 3 seconds off. You can adjust for this by reducing the pause by 7 milliseconds: "pause 243". If you need more accuracy, you could use BeanieBots's method to time the loop (insert the string of commands in place of his single command) and adjust the pause as needed. You could also time the loop when there has been a change and adjust for the number of times a change has been detected.

You could get finer control by reducing the pause to make more than 4 loops per second.
 
Top