08M2 Motor control.

shamu

Member
Hi all.

I'm trying to control the speed of a motor by counting the N° of revs per second, using a Hall effect switch.

The problem I'm having is that the AND condition appears not to be working on the IF THEN ELSE line.
I need this condition so that the program doesn't count the same pulse more than once.

Thanks.

' This program is to control the speed of a motor by counting signals from a Hall
' effect switch.

#picaxe 08M2
#no_data

setfreq m8

symbol revcounter = b1
symbol trig = b2

Main:

revcounter =0
trig =0

beginning:

if pinC.4=0 and trig =0 then
high C.1
revcounter = revcounter +1
trig =1
else
low C.1
let trig = 0
endif

goto beginning
 

Attachments

SAborn

Senior Member
Your program is so basic i can not see how it can work.

IMO you would need to use PWMout to control the motor speed and also need to use Pulsin to read the time between one pulse of the hall sensor and the next pulse, then you have a time variable of shaft speed to adjust PWM to suit rpm.

Bare in mind you will never get a perfect match for rpm due to other factors like load, but you will get a reasonable control.
 

shamu

Member
Hi.
I'm building the complete program bit by bit, this is just the part that will do the counting.
I have tried using PULSEIN previously but without any success, can you give an example?
 

SAborn

Senior Member
Hey, bit by bit is the way to do it, and that includes breaking the code into steps to understand how it works.

Below is a simple program to use pulsin and display the reading in debug, you will need to expand the variables window on screen in debug to show "word variables" (w0).
Then you should see in w0 the speed reading change as you apply load to the motor shaft.



Code:
Main:

Pulsin C.4, 1. w0

debug

pause 300

goto main.
 
Top