View Full Version : counter for counting magnetic microswich press
turkuaz
- 16th June 2007, 10:49
Hi Everyone.
I want to count microswich open-close positon to count disk rotation.
ı have a micro magnetic swich which is produce 2 signal when maghnetic disc rotating 1 time.magnetic swich debounce time is 20 uSec.
I use Pic16F877
This is my code:
..PORTA.4 input pin...
........
..........
loopHy:
IF PORTA.4 = 0 THEN loopHy
count = count+50
Lcdout $fe, $C0, #count:Pause 250(debounce time for slow rotation)
goto loopHy
........
is it Ok .or anybody give me advise.
Thanks.
turkuaz
- 17th June 2007, 13:04
Hi Everyone.
I want to count microswich open-close positon to count disk rotation.
ı have a micro magnetic swich which is produce 2 signal when maghnetic disc rotating 1 time.magnetic swich debounce time is 20 uSec.
I use Pic16F877
This is my code:
..PORTA.4 input pin...
........
..........
loopHy:
IF PORTA.4 = 0 THEN loopHy
count = count+1
Lcdout $fe, $C0, #count:Pause 250(debounce time for slow rotation)
goto loopHy
........
is it Ok .or anybody give me advise.
Thanks.
I solve this problem myself as follows:
.............
loopHy:
IF PORTA.4 = 0 THEN loopHy
count = count+1
While portA.4=1 Then
Lcdout $fe, $C0, #count
Wend
goto loopHy
.............................
It is working nice
thanks everyone.
mister_e
- 17th June 2007, 22:20
Carefull when you use reserved word... COUNT is also a PBP statement. You should change it to something else
Now ;) JUST FOR FUN, and as your current hardware is setuped to use it, try this one which use TMR0
ADCON1 = 7
pCount VAR BYTE
OldpCount VAR BYTE
CLEAR
TMR0 = 0
OLDPCOUNT = 1
Start:
pCount = TMR0
IF pCount != OldpCount then
LCDOUT $FE,$C0, #pCount
OldpCount = pCount
ENDIF
GOTO Start
turkuaz
- 18th June 2007, 09:07
Carefull when you use reserved word... COUNT is also a PBP statement. You should change it to something else
Now ;) JUST FOR FUN, and as your current hardware is setuped to use it, try this one which use TMR0
ADCON1 = 7
pCount VAR BYTE
OldpCount VAR BYTE
CLEAR
TMR0 = 0
OLDPCOUNT = 1
Start:
pCount = TMR0
IF pCount != OldpCount then
LCDOUT $FE,$C0, #pCount
OldpCount = pCount
ENDIF
GOTO Start
Thanks for your advice.
I chanced count to sayim(in Turkish)
I do not want to use timer because when disk begin to rotation ( which is slow rotation)micro magnet take to time to pass under the magnetic swich so swich is on position and count is going to count I do not this. I want only one time not elong with passing is going on.
Acetronics2
- 18th June 2007, 13:38
Hi Turkuaz,
Could you tell us what's your MAX RPM ( or half freq ...) counting rate expected ???
Will help for a solution.
I think we could detect only the Low-to-High ( or High-to-Low ) transitions, to get rid of the rotation speed span.
But the debouncing time must fit the max RPM !!!
Alain
Powered by vBulletin® Version 4.1.7 Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.