Help please, to detect a rapid 0-5V pulse

JPU

Senior Member
Thanks for looking,

I am trying to use the signal output from as brush-less motor controller to detect if the power to a motor should be stopped.

The brush-less controller is from Ebay and makes use of the HAL sensors on the motor. The controller works well but has a method to cap the current drawn by the motor by reading the voltage drop across a resistor on the PCB. If the motor jams then the voltage drop measured hits a certain level, the controller switches off (trips off) and has to be then switched on and off to reset it before is will work again. This won't work for me and so I am going to try and use a signal wire on the controller board to try and sense the motor stopping and switch off the motor before the controller trips off.

The signal wire pulses high (5V) 6 times and low (0V) 6 times for every full evolution of the motor.

Is there a way I can reliably count these pulses, bearing in mind the motor can be turning up to 7000RPM

If I can then I am hoping that I can then detect if there is a jam and stop the motor before the controller trips. According to the Chinese instruction there is a 4ms window to do this in ie the time the voltage drop must exist before the controller trips off.

If someone could please advise me and possibly has any other tips it would be appreciated. Im currently using a 08M2 to control the controller using Pins 3,4,5 to start/stop and speed up/slow down and so I do have a couple of pins free on the Picaxe.

Thanks for your help in advance.

JPU
 

hippy

Technical Support
Staff member
If I have read that right, you have to detect the motor having stopped within 4ms of it stopping.

At 7000 RPM that's one revolution every 8.67ms, a rising pulse edge every 1.4ms.

A PAUSE gets prematurely terminated on an interrupt, so you could use something like this to determine if a pulse had happened within 1.5 ms, 2 ms here ...
Code:
MotorRunning :
  Do
    stopped = 1
    SetInt ... , ...
    Pause 2
  Loop Until stopped = 1
MotorStopped:
  ...

Interrupt:
  stopped = 0
  Return
You would want to run at the fastest speed, SETFREQ M32 on an 08M2, to minimise overhead, and that would mean increasing to PAUSE 12.

But I'm not sure how that would work at lower speeds where pulses will take longer to arrive.
 

AllyCat

Senior Member
Hi,

Do you actually want to "count" the pulses or just detect when there is a gap of more than (say) 2 ms between them (i.e. the motor has stalled). I will assume the latter. What else is the program doing at the time? i.e. can you poll an internal flag (at better than a 4ms rate) or must you use an interrupt? Bear in mind that M2s can be interrupted ONLY by digital pin-level changes, not by any internal signals.

The simplest solution might be an external capacitor which is kept charged by the 5v pulses and discharged by a resistor to ground with a time constant around 1 ms. The analogue voltage will decay down to the digital threshold (~1.5 volts) in about one time-constant and could generate an interrupt.

If you want a totally "software" solution then there are several possibilities: For example the internal S-R latch, but this cannot be read directly by software so needs two pins (linked together). The "Timer 1 Gate" hardware has several latches which can be used independently of the timer itself and read internally, but the "best" solution is possibly the "Interrupt On Change Latch" flags, which can be triggered on BOTH edges at the same time. These can't generate a direct interrupt in any M2, but can be polled with a PEEKSFR. So if you can poll the Register/Flag every few ms then you could stop the motor drive if no pulse edge has been detected.

More details are available on any of these methods if you need them, but as hippy has (just) indicated, your timings do look rather "marginal".

Cheers, Alan.
 

erco

Senior Member
If you want a vintage hardware solution, this sounds like the perfect application for Forrest Mims' LM555-based "Missing Pulse Detector" from his fabulous 1982 "Engineer's Notebook II" sold at Radio Shack. You could interface this to a Picaxe easily, although per Hippy & Alan, a Picaxe could probably be used without external circuitry.
 

Attachments

OLDmarty

Senior Member
If you want a vintage hardware solution, this sounds like the perfect application for Forrest Mims' LM555-based "Missing Pulse Detector" from his fabulous 1982 "Engineer's Notebook II" sold at Radio Shack. You could interface this to a Picaxe easily, although per Hippy & Alan, a Picaxe could probably be used without external circuitry.
Hahaha, now *THAT* is a classic book, i still have mine too ;-)
 
Top