Timer problem - advise?

Man_in_uk

New Member
Hi,
I must first say that the reason I love the Picaxe is due to the Logicator block diagram method of programming. It is the only way I can make up programs so please bear this in mind when suggesting a solution.

I am just about to build a project and for reliability I have chosen to use an X2 chip as they have the RST pin. This causes me problems as I now do not have the luxury of multiple threads in the M models.

I would like to build a device that will run two separate timers.
timer 1 cycles on & off 2 sec interval
timer 2 cycles on and off between .5 & 1.5 sec depending on how a bank of DIP switches have been set

I cannot work out how to create timer 1 a constant, when timer 2 will change?
Can this be created in Logicator?

Thanks
 

hippy

Technical Support
Staff member
Without using multi-tasking you can solve the problem by having a fixed loop time. Count the time elapsed and then, alter the the time required for each timer has elapsed toggle an output for example, something like -
Code:
Do
  Pause 10
  timer1elapsed = timer1elapsed + 10
  timer2elapsed = timer2elapsed + 10
  If timer1elapsed >= timer1period Then
    Toggle TIMER1_OUT
    timer1elapsed = timer1elapsed // timer1period
  End If
  If timer2elapsed >= timer2periid Then
    Toggle TIMER2_OUT
    timer2elapsed = timer2elapsed // timer2period
  End If
Loop
You can set timer1period to 2000 ( 2000ms, 2 second ) and within the loop you can read the DIP switch and set what timer2period should be.

And you could do all that with a Flowchart, or Blockly, though it would probably be easier done as a Basic program as above.
 

Man_in_uk

New Member
Cheers hippy.
You have made me see this problem in a different way and now I think I can work out how to build this with a flow chart.
 

Man_in_uk

New Member
Do you know if it is possible using flowcharts to measure time in milliseconds?

I wish to monitor an input. When it goes high, count in milliseconds until the pin drops low.
 

hippy

Technical Support
Staff member
You could potentially count elapsed time in a loop, have some flowchart equivalent of ...
Code:
Do : Loop Until inputPin = 1
w0 = 0
Do While inputPin = 1
   Pause 10
   w0 = w0 + 10
Loop
 

Dartmoor

Member
I must first say that the reason I love the Picaxe is due to the Logicator block diagram method of programming. It is the only way I can make up programs so please bear this in mind when suggesting a solution.
A useful feature of PE6 is the "convert" button when using the Logicator method for programming. This converts your flowchart into basic which can help with understanding. Works for me!
 

Man_in_uk

New Member
A useful feature of PE6 is the "convert" button when using the Logicator method for programming. This converts your flowchart into basic which can help with understanding. Works for me!
I have looked at this before but I need a button that works the other way round.
Load a page of BASIC and convert it into a flowchart :)
 

Dartmoor

Member
There is a feature that is half way there "add basic command sequence"?
You can insert a block of basic code & write your flowchart around that.
 
Top