Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

wind speed meter with direction using PIC16f877A, rotary encoder and LCD 16x2

Status
Not open for further replies.

mokh

New Member
hi all!

im new here. i would like to ask for programing a PIC16F877A for rpm measurement. the input is from the hall effect sensor which giving a pulse once for each rev. the output is on 16x2 characters LCD display.

the hall effect sensor
the output is a pulse (high to low) once for each rev.
connected on PORTB.0(int/RB0)

the PIC16F877A
using 20MHz crystal.

the LCD
16x2 characters.
data register on PORTD
control register on PORTB.5,6,7

rotary encoder
absolute type
127 position

i write the program in BASIC. now, im stuck on the RPM measurement. i refered on a site that measure RPM using interrupt here. btw, he is using PIC 16f84 and the program writen in C language.

i having difficulties on translate it to BASIC esp on the interrupt part. if u look at the site, the project giving an option to run in 1 ppr(pulse per rev), 6ppr and 60ppr. for my project there is no option for that. only 1ppr.

please give me suggestion or guide especially on the interrupt part.
 
im done with the speed measuring.

now, i dont have any idea on the direction detection part.

im using absolute rotary encoder for direction detection. it is a 128 resolution. meaning that it have 128 position detection. each position giving an 8-bit binary.

question is how to scan an 8-bit port and compare it on a 128 data and then, display the output in degree?
 
mokh said:
im done with the speed measuring.

now, i dont have any idea on the direction detection part.

im using absolute rotary encoder for direction detection. it is a 128 resolution. meaning that it have 128 position detection. each position giving an 8-bit binary.

question is how to scan an 8-bit port and compare it on a 128 data and then, display the output in degree?

hi,
As its an absolute 8 bit binary code, make 0x00 = 000deg [North]

Read the binary value from the encode and multiply it by 360/128 to get the angle or use the binary code to address a program table.

EDIT: why have you decided to drop the wind speed measurement?
 
Last edited:
// im not droping the speed measurement. i did the programming and its already work! :)

for direction measurement, the 128 position is encoded in grey coded binary. i wonder the scan-and-calculate method will work?

my idea is to put all the 128 8-bit grey coded binary to the PIC and then using instruction such as scan-and-compare to the codes.

but i dont know how to implement it in the PIC.

btw, i write my program in PBP(probasicprogramming)...
 
mokh said:
// im not droping the speed measurement. i did the programming and its already work! :)

for direction measurement, the 128 position is encoded in grey coded binary. i wonder the scan-and-calculate method will work?

my idea is to put all the 128 8-bit grey coded binary to the PIC and then using instruction such as scan-and-compare to the codes.

but i dont know how to implement it in the PIC.

btw, i write my program in PBP(probasicprogramming)...

hi,
If you have the program space and your Basic can do Tables, why dont you simply use the encoder 8 bit output as a Table address.

You have only 128 entries in the table, set encoder code '00000000' [0x00] as the address for North '000' degrees.

Or like I said previously, calculate from '000' degrees, using the encoder output, which each change gives equivalent to 360/128 degrees/increment.

Example: if the encoder output is equivalent to say, #64, then 64 * [360/128] = 180 deg.

Do you follow that?
 
You can convert Grey to Binary by doing,

bin = grey Xor (grey >> 4)
bin = bin Xor (bin >> 2)
bin = bin Xor (bin >> 1)

HTH

Mike.
 
i dont get it. can someone show me the exact coding? (in PBP)
for the 128 direction, i attached here the table

hi,
The table you have posted shows the decimal value for the code converted from binary.
The position is the step by step position from zero of the encoder shaft.

Remember, you have 0 thru 127 steps of the shaft, ie; 128 positions.

The angular measurement you trying to determine is in 360 degrees.

So, 360/128 = 2.8125 degrees per shaft step, as you know the decimal value
of the gray code for each step, multiply by 2.8125 to give the [360] angular position.

OR use a calculator and create a TABLE for the 128 discrete code positions and use the encoder output
as an address to read the Table value from within the PIC program.

Does this help?
 
the 1st idea might not working bcoz the decimal numbers is not in normal order. i dont see any relation between position 0 and 1, and position 1 and 2, for example.

for the 2nd idea, i dont really get it. but i think creating a table in PIC might work. problem is, i dont know how to write a table of 128 positions in PIC.

i did som reading on it but mostly they show for litle row of data. for 2 bits only. for 8 bits, never seen it on books.
 
hi,
Can you confirm that the encoder output is 'gray' code.?
Do you have an sample figures?

Where did you get that Table you posted?

I have written a program in assembler, that converts the gray to binary and then multiplies the binary by 2.81 to give an angle, 0 thru 360 degrees.
 
it is a grey code. as stated in the datasheet.

the table i posted before is the table output given in the datasheet of rotary encoder that im using in this project.

u can see it on http://www.bourns.com/components.aspx?cmsphid=7631383|7163299|2829252#ce
look for 'EAW'.
 
mokh said:
it is a grey code. as stated in the datasheet.

the table i posted before is the table output given in the datasheet of rotary encoder that im using in this project.

u can see it on http://www.bourns.com/components.aspx?cmsphid=7631383|7163299|2829252#ce
look for 'EAW'.

Downloaded the data from bourns, will look thru it.
BTW its 'Gray' code.;)
 
opss...my bad.

sorry about that. hahaha..

there are 2 types of rotary encoder, absolute and incremental. to make programming easier, which one is better?

i might consider to change the encoder for programming purpose.
 
mokh said:
opss...my bad.

sorry about that. hahaha..

there are 2 types of rotary encoder, absolute and incremental. to make programming easier, which one is better?

i might consider to change the encoder for programming purpose.

hi,
Worked thru the datasheet, the shaft position seems to have no relationship with the Gray code?:confused:

It looks as though a conversion Table maybe required.? refer the gif
 
Last edited:
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top