Counting a pulse - Please Help!!

TechFrank

New member
Im trying to teach myself basic after years of not using it.
the project is the following:

Count a pulse on a pre-set pin say pin6 after 5 pulses, goto main:
If there is no pulse within 10 seconds high pin1 & high pin2

This may be very simple for some of you but i cannot work out what i need to get this to work.
 

hippy

Senior Member
Welcome to the PICAXE Forum.

Counting and responding to pulses in a time period can be quite tricky, can depend on exactly what you want to happen under quite a few different scenarios, but one option is the following which might give you some ideas. Not tested on real hardware but does run under PE6 simulation -
Code:
#Picaxe 08M2

Symbol PULSE_PIN   = pinC.3
Symbol ACTIVE      = 1

Symbol elapsedTime = w0 ; b1:b0
Symbol pulseCount  = b2

Main:
  elapsedTime = 0
  pulseCount  = 0
  Do
    Do
      Pause 10
      elapsedTime = elapsedTime + 10
      If elapsedTime >= 1000 Then TimedOut
    Loop Until PULSE_PIN <> ACTIVE
    pulseCount = pulseCount + 1
    If pulseCount >= 5 Then HadFivePulses
    Do
      Pause 10
      elapsedTime = elapsedTime + 10
      If elapsedTime >= 1000 Then TimedOut
    Loop Until PULSE_PIN = ACTIVE
  Loop

HadFivePulses:
  SerTxd( "Had Five Pulses", CR, LF )
  Goto Main

TimedOut:
  SerTxd( "TimedOut", CR, LF )
  Goto Main
 
Top