Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Measuring speed using a rotary optical encoder through a PIC 16F877 microcontroller

Status
Not open for further replies.

bm_059

Newbie level 3
Joined
Jun 28, 2012
Messages
3
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,298
Dear friends

I am doing a project where i need to measure the speed of my motor shaft. I am using a incremental rotary encoder which will give 1024 pulses
per revolution. This output will enter a PIC 16F877 micro-controller. I need to do programming in mikroC to calculate the speed. I have no clear idea, how to program the micro-controller. i am very new to this subject.

Kindly help me.

Relying on your usual cooperation.

Thanks

Kind regards

bm_059
 

Hello,

in a simple case you only need a timer which starts and then stops if 1024 pluses are count. So you get the time for one rotation and can calculate the rotation speed. I think the CCP-module of the PIC could a good idea for doing this application.
 

Thanx for ur reply.

can u help me how to program the pic for above case with ur advise. (it will be very much helpful if u could give me some programming codes.)
 

Hi bm_059,

You have to do 2 things:
1) You need to count impulses from encoder - for this you have to use external hardware interrupt on e.g. RB0
2) You need to measure time, and then to calculate speed as impulses/time

In such applications I always use PIC 18Fxxxx family, because 18Fxxxx PICs have 2 interrupt priority level.

What I'm talking about?!?! Simple explanation:
In normal case you will have at least a few revolutions per seconds, meaning, you will have let say 3000 impulses every second. It is very important to not miss a impulse, so in this case I will make HI priority external hardware interrupt on RB0/RB1 pin for counting of impulses.
On other side, you have to measure time for calculation of speed. For this purpose a timer interrupt on every 100ms - 500ms (depends how offen you need to calculate speed) should be made as LOW priority interrupt.
Why?
Because encoder interrupt will occur every 0.333ms (in this example), it is likely to happen that while PIC is in time interrupt encoder count happen and without hi/low priority this count will be lost...

In case of LOW/HI priority, while PIC is in timer interrupt if encoder interrupt occurs, PIC will interrupt timer interrupt, execute code for encoder and than go back to execute timer interrupt where stopped... In this case you will not losing impulses, and if you write timer interrupt routine wisely you will get good calculation speed results.


Best regards,

Mr.Cube
 

programming codes please.....................
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top