Input pulse's to long

Roy Spiller

New Member
Hi I am new to the picaxe. I am using the picaxe-40x2 and the problem I have is trying to count the pulse's from a brushless motor with three hall sensors set at 120 degrees apart, they are connected a/pin d.1, B/pin d.2, and C/pin d.3. I only need to count off one of the sensors the others are for sensing direction. when I try to count from the rotating motor it is fine with a basic count routine. however when the motor slows down so the on pulse will be on for a while or stops on the sensor it will continue to count? the output pin I am using is a.5. I think it needs to trigger of the leading egde or some sort of flipflop? I don't have any program for this section at the moment.
 

eggdweather

Senior Member
The format is COUNT pin, period, wordvariable - See more at: http://www.picaxe.com/BASIC-Commands/Digital-InputOutput/count/#sthash.3RZ7UZzJ.dpuf
So what value have you set 'period' at ? 1000 would be 1-sec at 4Mhz. It appears to count until 'period' has timed-out and it does as you need, because it only counts on transitions of low-to-high. Even if there is no input or it stops as in your case, the programme flow will continue when the period time is complete, so you need to test for that event and resume counting when it exceeds some rpm.
Assuming:
symbol rpm w0
symbol last_rpm w1
symbol current_rpm w2

last_rpm = 0

start:
gosub rpm_measurement
gosub display_current_rpm
goto start

rpm_measurement:
if last_rpm < 10
COUNT a.5, 1000, current_rpm 'test it now
if current_rpm > 10 ' Now it's going faster again
last_rpm = current_rpm
endif
else
count a.5,1000,current_rpm
endif
return
~~

Is what I'm thinking, but it's going to take 1-sec to cycle, whatever happens, but someone is bound to find a better way of doing this.
 

AllyCat

Senior Member
Hi Roy,

when the motor slows down so the on pulse will be on for a while or stops on the sensor it will continue to count?
Welcome to the forum. Are you saying that it doesn't work, or you think that it might not? In principle, the COUNT command should count edges over the specified time (and thus stop counting when the motor stops). If it doesn't then you may have a noise/interference problem, or a bug in the program.

There are many possible methods/solutions, but we need to know what is (or if) there is a problem with some specific code. A suitable solution may depend on the maximum speed of the motor pulses (per second), what is it?

Cheers, Alan.
 

inglewoodpete

Senior Member
Depending on the speed of the motor, it may be appropriate to measure the duration of each pulse (Command: PulsIn) rather than the number of pulses in a given period.
 

Roy Spiller

New Member
Hi sorry for the delay.
What i am trying to do is count the pulses from one of the hall sensors (pin d.1) when it hits a fixed number of pulses it will give an output at (pin a.5). I know it sound simple, but i connot get it to work the signal in is a good clean 5v square wave?
Roy
 

hippy

Ex-Staff (retired)
What i am trying to do is count the pulses from one of the hall sensors (pin d.1) when it hits a fixed number of pulses it will give an output at (pin a.5).
You probably need to count the pulses by polling and waiting for highs and lows. Something like this which activates A.5 when 10 pulses have been counted -

Code:
#Picaxe 40X2
SetFreq M16
Do
  Do : Loop Until pinD.1 = 0
  Do : Loop Until pinD.1 = 1
  b0 = b0 + 1
  If b0 >= 10 Then
    High A.5
  End If
Loop
 
Top