PIC16F1827- Trying to make a pulse period counter

Thread Starter

Oliver Wallin

Joined Jul 31, 2017
4
Hi!
I'am currently studying mechatronical engineering and am currently working on a steering project for a ventilation system.
Our system has a motor that is connected to a disk with holes around its perimeter. We want to read the RPM of the disk with an optical sensor which is sending out pulses to our micro controller.
We are completely novice with programming a pic controller and has reached a problem we need help with.
TMR0 function is used to count the pulses, so far has we gotten.
Now we want either to measure the time between the pulses or count how many pulses there is within a predetermined timespan in order to calculate the RPM.
Our ideas is something like the arduinos "millis()" function to get the time at the different timepoints.

Hopefully I explained it so you understand!
We would really appreciate some help!
 

be80be

Joined Jul 5, 2008
2,072
If you posted some code you did that would help.
No one going to write it if you don't show you tried.

And a circuit of how you reading the disk parts you used and pins are really helpful.

Don't need it you use the timer and a gated input count the tick's and how many clock tick's.

Open the gate start the timer count the gate tick's stop gate at a set point and print out
the tick's as was counted.
Then turn that info into rpm.
 
Last edited:

Sensacell

Joined Jun 19, 2012
3,453
Use the chip's built-in "Capture-Compare" hardware, it's designed to do exactly what you want, with greater accuracy and relatively simple code.
 

LesJones

Joined Jan 8, 2017
4,190
If you want to see a design using the capture- compare module (Using the capture mode.) Then there is a tachometer I designed several years ago on my website. It uses a PIC16F628. For low speeds it measures the time of one revolution and converts the time to an RPM reading, for higher speeds it will measure the time over several revolution to give a more stable reading. The source code is included. There is also detailed description of how it works.

Les.
 

Picbuster

Joined Dec 2, 2013
1,047
Simple problem.
use a counter start and stop on interrupt.
Make sure that counter runs al least 10 x the expected interrupt.
Skip n cycles (rotations) allowing calculation or wait n pulses.
calibrate by countervalue x correction.

Good luck.

Picbuster
 

spinnaker

Joined Oct 29, 2009
7,830
I can help you with your project. I can give you a code in 2 hours.

I can give the TS code in 1,5 hours. :eek:

But that wouldn't be helping the TS now would it?

BTW thread is already over a month old with no updates. TS has likely moved on. Why do you keep posting to old threads with this same offer?
 
Top