PDA

View Full Version : tachometer



aztaig
- 10th August 2008, 07:41
Hello

This is my first posting. Hope not to be much of a pain with this question. But I am using a 16F84 to make a tachometer. I am reading the pulse from a photo interrupt. I can get the MCU to read the pulsin signal I'm just not sure if I am processing the data correctly. Please bear in mind that I am a complete novice at this. Extra info I guess would be that I am taking a pulse off a small dc motor with a 1.5" disk as an encoder. I am using 2 holes on a 1.25" bolt center, each hole 1/8" diameter. If anyone can point me in the right direction, it would be greatly appreciated.

skimask
- 10th August 2008, 08:23
Show some code! What have been your results so far? What's the problem? What's working? What's not working? Is anything working?
http://www.picbasic.co.uk/forum/showthread.php?t=1742

aztaig
- 10th August 2008, 19:18
Well here is my code, not much to it. Again I am complete novice and I think I'm trying to over simplify the code.

'Program --- Encoder ---
'Initialize variables

symbol trisb = 134
symbol portb = 6
symbol pulse = w1
symbol rpm = w0

'Initialize trisb for input

poke trisb, 1 'Set RB0 to input by bitweight

'Start reading photo opt

start:
pulsin 0, 1, pulse 'Read high pulse off RB0, record to var. pulse
rpm = 50/pulse 'Calculated rpm from pulse
serout 1, n2400, (254, 1)
serout 1, n2400, ("RPM = ", #rpm)

goto start

I was just reading a thread about the math capabilities of the 16F84 and I think I'm calculating something that is not compatible with the MCU. When I multiply the 50 and pulse I do get a result to the LCD. Of course the result is inverted from what I want but the basic code works. Not sure how to handle the decimal I guess is my problem.

skimask
- 11th August 2008, 01:43
I think you've got the general idea, but the execution isn't the best.
Check the COUNT command and let it count for a second, divide by how many slots are in the wheel, then multiply the result by 60. That should give you RPM. You won't get the best resolution, but the idea should trigger some better ideas for you.

Archangel
- 11th August 2008, 06:42
Count is what I was thinking too but I do not see it as an option in PBC
http://www.melabs.com/resources/pbcmanual/

skimask
- 11th August 2008, 13:54
Doh! You're right...
Well, then, it's likely going to be a matter of setting up one of the timers on the PIC manually, waiting for a pulse, starting the timer, waiting for another pulse, then doing the math. For instance, running a 4Mhz PIC, set up a 16 timer running with no prescale. Set the timer to zero. Wait for a pulse, start the timer. Wait for another pulse, stop the timer. Read the timer and save the values.
Assume you get a count of 1,000 from the timer registers and you've got 1 slot in the wheel. That means it took 1,000us to get one revolution (timer ticks at one count per us @ 4Mhz/no prescale). In one second, you get 1,000 revolutions. In 60 seconds, you get 60,000 revolutions.
1,000,000 / 1000 = 1000 * 60 = 6000
If you get 2,000us per pulse,
1,000,000 / 2000 = 500 * 60 = 3000
Problem is, PBC doesn't support anything over a word variable. So hopefully, the O/P can come up with some creative math to solve that problem.
We'll see what happens...