detecting very short duration input pulses

JoeFromOzarks

Senior Member
Howdy folks! I’m looking for a method of detecting/eliminating short duration inputs, something like contact bounce, four inputs simultaneously.

When a PICAXE input changes state for less than, say, 100ms, 250ms or so, then the transition is considered invalid and is ignored. If the input changes state for more than, say 100ms, 250ms or so, then the transition is considered valid and the PICAXE acts on it, turning on an output.
(In this case, a PICAXE input HIGH means the input circuit is normally open or OFF, a PICAXE input LOW means ON. The input signal is inverted.)

The actual circuit looks something like this:
--14M2 with 4 digital inputs and 3 digital outputs. (When any of the inputs go LOW (turned ”on”) then the three outputs go HIGH - while any of the inputs are LOW.)
--Any one (or more) of the four inputs can be turned “on” (sent LOW) in no specific order.
--Under normal circumstances, an input is transitioned for duration's of about quarter-second (100-250ms) or GREATER is considered valid.
--Standard 5VDC circuit, stable power supply.

My PICAXE coding inexperience is massive. <grin> I don’t have any code to share but I’ve considered DO…LOOPs, but that locks in one input at the expense of ignoring the other three. I eyeballed interrupts but maybe I should’ve dedicated more time to using the 18M2. And then there is that “time elapsed” thing, using a 14M2 or 18M2 determining if the elapsed time is greater than 100ms or 150ms, or so.

Forum friends, what would you suggest? (The attachment is for giggles only and has nothing to do with this project!) :)

Thank you!!

joe
 

Attachments

premelec

Senior Member
Taking the low voltage approach: Consider a capacitor on a high impedance input fed by a diode and if necessary a bleed resistor across the diode - then use READADC to discern if a short [pulse has happened.... capacitor will stretch a short pulse after disconnect decaying in time with bleed resistor- [such assembly on each input...]
 

Janne

Senior Member
You could have a timer-tick variable, that is incremented during each main loop cycle, so that it corresponds to a time delay of say 10ms. Then if an input is "active", set a variable per that input to indicate a timer value to turn it on. If the said input returns to zero, reset the the variable, or if timer tick value exceeds the value on the variable, set outputs high. Just an idea to get you going, I'm sure there are better implementations too :)
 

Flenser

Senior Member
When a PICAXE input changes state for less than, say, 100ms, 250ms or so, then the transition is considered invalid
I'm not sure where you got this from. The times of 100ms & 250ms seem very long to me.

Have you looked at the pulsin command for detecting short pulses? This info from the manual for the pulsin command:
State is a variable/constant (0 or 1) which specifies which edge must occur before beginning the measurement in 10us units (at 4MHz resonator)
 

inglewoodpete

Senior Member
Hi Joe, As others have already said, 100 to 250mS is quite a long time when it comes to microcontrollers. Usually, two samples of an input within
a period of 40 to 100mS is sufficient to detect and confirm an external event.

A few years ago, I wrote a program that demonstrates how a keypress can be timed and the response can be controlled according to the length of the keypress. Have a look here, where I documented the project.
 

hippy

Technical Support
Staff member
As said; 100's of milliseconds is a long time for a PICAXE so it should be possible to do what you want using BUTTON commands or implementing something similar yourself. This example monitors four input pins and only reports once whenever they are held high for one second -

Code:
Symbol PIN_A = pinC.0
Symbol PIN_B = pinC.1
Symbol PIN_C = pinC.2
Symbol PIN_D = pinC.3

Symbol LOOP_TIME = 10 ; 10ms

#Macro Test(pinBit,wVar,label)
  If pinBit = 0 Then
    wVar = 0
  Else
    wVar = wVar Max 9990 + LOOP_TIME
    If wVar = 1000 Then label
  End If
#EndMacro

MainLoop:
  Do
    Test(PIN_A,w1,GotPinA)
    Test(PIN_B,w2,GotPinB)
    Test(PIN_C,w3,GotPinC)
    Test(PIN_D,w4,GotPinD)
    Pause LOOP_TIME
  Loop

GotPinA: SerTxd( "PIN A held", CR, LF )
         Return

GotPinB: SerTxd( "PIN B held", CR, LF )
         Return

GotPinC: SerTxd( "PIN C held", CR, LF )
         Return

GotPinD: SerTxd( "PIN D held", CR, LF )
         Return
 

kranenborg

Senior Member
Joe, I am intrigued by what application related to the question you have in mind, because the included picture keeps on distracting me ... . Maybe that helps solving it.

Related but still slightly OT and perhaps not a solution to this particular problem, but for the general case of catching very fast events/pulses on a single input pin of a Picaxe, the SR-Latch can be used to capture very short pulses and store this event as a memory bit, which can then be sampled by a Picaxe program reading its output state directly (or alternatively and even better for dealing with an asynchronous event:: feeding the latch output to an interrupt pin). In this way the microcontroller fast hardware is solely responsible for and capable of registering and signaling a fast event, which can then be processed later by the relatively slow Basic program. See for example this link.

/Jurjen
www.kranenborg.org/electronics
 
Last edited:

JoeFromOzarks

Senior Member
WOW!!

The responses are excellent, I love this place!! I’ll look into each and every post and report back.

Meanwhile:

Yes, 100ms – 250ms I a VERY long time for a microcontroller, but it’s a reasonably short amount of time as far as the open collector device output to the PICAXE input for this application. (For the record, at my age, 250ms is not a very long period of time at all, not one bit!! HAHAHAHAHA!!!)

Premelec: Your suggestion is excellent, and at the beginning of the project I built such an assembly. I really want a firmware solution though.

Janne: I tried that suggestion but had trouble considering four inputs simultaneously. I used incrementing bytes to count when to bail but had trouble when the transition was valid. I don’t know how to access the timer info on a 14M2 or 18M2.

Flenser: Yes 100ms and 250ms is forever when eyeballed by a microcontroller, but it’s extremely quick for this application. Those times are not relative to the PICAXE input and I’m not reporting a defect, it’s relative to the common collector output of the devices talking to the PICAXE inputs. I hope I explained that properly.
I will look at PULSIN, thank you. Can four PULSIN commands run simultaneously? I haven’t tried it.

Inglewoodpete: I will build your linked project as an exercise but the DO…LOOPs won’t allow four input detecting simultaneously. I hope I didn’t jump to a conclusion; I will study your code.

Hippy: You solution looks to be the most applicable, I will give it a try and report back. Thank you!!

Kranenborg: Ignore the image I posted, it’s for a good laugh and nothing else. It is not related to my project at all. <grin> I’m retired and as such, easily amused.
Your suggestion looks to be applicable also and I’ll build a test rig and try it. Thank you!


Thank you everyone! I’d better get to work.

:) joe
 
Top