Counting impulses

Pivrnec78

New Member
Hi,
I do not know where to include this problem, so I write it here.
I need to create a PICAXE comparator. I need to load (count) impulses on the pin1. When pin1 appear first impulse then light up LED1. Then I need to load (count) impulses on the pin2.
I do not know the frequency - time will be different. The time between pulse1 and pulse2 will be different from the time between pulse2 and pulse3.
And when pin2 = pin1 then turn off LED1, turn on LED2 and reset pin1 and pin2.
The number of pulses per pin2 will not be greater than pin1.

The "COUNT" command I think can not be used. Because I do not want to count (measure) frequencies, but add and compare the number of impulses.
Now I work with 74HCT193 - 4-Bit Up / Down Counters, but I need to expand. 4-bit be few, I need 8-bit ...
 

AllyCat

Senior Member
Hi,

Welcome to the forum. Yes you are correct that COUNT is not useful to you.

Your problem depends very much on the width and frequency of your "pulses", and your programming abilities. If any individual "event" (e.g. a pulse rise, fall or "skew" between pulses on separate pins) occurs less often than about 10 ms then it should be quite "easy" to do with a "polling" software loop (or maybe multiple loops using PICaxe's "multitasking").

If events occur more often than approximately 1 ms* then it's probably not possible with a PICaxe and you need to look elsewhere for an assembler or hardware solution. Between those two time limits it may be "possible" with a PICaxe, but you may need to use more "advanced" programming methods, such as controlling the on-chip hardware with POKESFR commands.

*If the pulses are "narrow" (e.g. a few microseconds or more) but all other times exceed 1 ms, then it may be possible to capture those pulses using some of the on-chip hardware capabilities.

Generally, the actual number of pulses will not be an issue; PICaxe can normally handle numbers up to 8 bits (255) or even 16 bits (65535) as fast (or slowly) as any other numbers.

Cheers, Alan.
 

Pivrnec78

New Member
Hello,
I need to calculate a train axis on my model railroad. Now I have a TTL logic with reversible counter 74193 and with another logic.
Because I need to know when the track is busy (train on track) and when it's free, so I have TTL 74193.
I can use 74193 to PICaxe also, but it is another component that can make a mistake. In addition, now I have 4-bit and need 8-bit.
Probably the most unfortunate for me will use 2x 74193 and then process the signal over PICaxe because my programming knowledge is almost zero.
 

darb1972

Senior Member
I think the forum members might need a bit more information to assist further.

For example, what sort sensor/s are you using? Are there several? If so, how far apart are they spaced? How fast can the trains travel? Is it possible that a train can stop over a sensor and therefore still make a track "busy" but not provide you with a pulse???

Maybe post some photos of your setup.

I think if you were to search "train" I vaguely remember previous threads discussing a similar issue. Maybe the content in these threads might assist.


Regards
Brad
 

hippy

Technical Support
Staff member
If this is a 'track occupied' indicator system, counting trains in and subtracting trains out, one can do that fairly efficiently using -

Code:
#Picaxe 08M2

Symbol incBtn       = b0
Symbol decBtn       = b1
Symbol counter      = b2

Symbol OCCUPIED_LED = C.1
Symbol CLEAR_LED    = C.2

Do
  incBtn = incBtn & 1 * 2 + pinC.4 ; Inc input
  decBtn = decBtn & 1 * 2 + pinC.3 ; Dec Input
  If incBtn = 1 Then : counter = counter Max 254 + 1 : End If
  If decBtn = 1 Then : counter = counter Min   1 - 1 : End If
  If counter = 0 Then
    Low  OCCUPIED_LED
    High CLEAR_LED
  Else
    High OCCUPIED_LED
    Low  CLEAR_LED
  End If
Loop
On a physical chip and when Simulated; b1 will increment whenever C.4 is taken high, decrement whenever C.3 is taken high. The LED on C.1 will be lit when the track is occupied, the LED on C.2 will be lit when the track is clear.
 
Top