Forum Menu




 


Log in Problems?
New User? Sign Up!
AVR Freaks Forum Index

Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Author Message
kameleon89
PostPosted: Feb 15, 2012 - 06:09 PM
Newbie


Joined: Feb 15, 2012
Posts: 5


Maybe I could have titled the topic differently, but here goes. I have a college project, and what I'm trying to do is to make a tachometer using an ATMega16A (on a kitboard), an LCD, and an improvised encoder.

The encoder problem is most puzzling to me. I've been to all the shops around town, and I couldn't find any encoders for sale. Since I have just a few days left to do this, ordering one online and waiting for delivery is out of the question, so I took my old ball mouse and disassembled it.

Now, I noticed that the IR detector on one side of the encoder wheel has 3 pins. Later, I figured that it must be because it's a double detector so the mouse can determine the direction of movement.

How would I then connect it to the ATMega? If I wanted to connect it to an interrupt pin (PD2 or PD3), I guess I need it to switch 5V (Vcc) and 0V on that pin to trigger interrupts, and I don't know how to get the right voltage out.

I used a multimeter to measure voltages between the 3 pins while the PS/2 cable was plugged in the PC; two outer pins produce 0.05V between them, and 0 when I put a piece of paper between. The voltage between the inner pin and both outer pins was 2.05V when uninterrupted, and 3.7 with the paper between.

That means it would probably be best to use the two outer pins, but can I somehow amplify the max of 0.5 V to 5V that is (i presume) needed for the input PIN of the AVR?

Thanks in advance, pictures will be provided if needed.
 
 View user's profile Send private message  
Reply with quote Back to top
Kas
PostPosted: Feb 15, 2012 - 07:37 PM
Resident


Joined: Nov 06, 2005
Posts: 592
Location: Vilnius, Lithuania, Continental EU

Mice encoder example diagram can be found for example at:
http://www.cqham.ru/projects/dds_20synthesizer_20kit_20.htm, the bottom pic.
For IR tacho sensor only single (LED to optosensor) optocoupler is needed.
 
 View user's profile Send private message  
Reply with quote Back to top
bobgardner
PostPosted: Feb 15, 2012 - 07:41 PM
10k+ Postman


Joined: Sep 04, 2002
Posts: 21257
Location: Orlando Florida

You dont need a quadrature encoder with 4 positions unless you need direction as well as speed. For a tach, you just need an led and a cadmium sulphide cell. Put some whiteout on the part thats turning and black sharpie on the other side. Shine the led on the shaft. Pull the cadmium sulphide cell up to 5V with a 10K resistor. Look on the scope while its turning. If you see any wiggle at all, you should be able to see that with the AVR analog comparator.

_________________
Imagecraft compiler user
 
 View user's profile Send private message Send e-mail Visit poster's website 
Reply with quote Back to top
kameleon89
PostPosted: Feb 16, 2012 - 08:22 PM
Newbie


Joined: Feb 15, 2012
Posts: 5


Hmm, I figured something out. The sensor on the encoder itself gives quite low voltages, but before these reach the PS/2 connector, they get amplified. By connecting one of the contacts for the connector's pins on my AVR's INT0, I managed to get voltage changes big enough that turning the encoder wheel sends interrupt signals to the uC.

I asked a few questions around how to turn these impulses into rpm value, and what I was planning to do now is to set up a timer, that counts a short period of time, so that the uC knows how many impulses were registered in that time period and thus calculates rotation speed. I've set the INT0 to rising edge, and it should work nicely.

True, I don't need the two-directional system the mice use, but it should suffice. Hope everything goes right...
 
 View user's profile Send private message  
Reply with quote Back to top
bobgardner
PostPosted: Feb 17, 2012 - 01:09 AM
10k+ Postman


Joined: Sep 04, 2002
Posts: 21257
Location: Orlando Florida

Since you are short on time, I suggest just polling the sensor till it goes hi, read the free running timer into variable t1, poll the input till it goes lo, poll it till it goes hi a second time, read t2. You now can take as long as it takes to calc deltat=t2-t1, mutiply ticks-per-second, and you have the period in seconds. Invert that to get RPS. Mult by 60 to get RPM. Display it on lcd or out the serial port. Turn in assignment. Tell the AVRfreaks that they have helped you get an "A".

_________________
Imagecraft compiler user
 
 View user's profile Send private message Send e-mail Visit poster's website 
Reply with quote Back to top
Handi3
PostPosted: Feb 17, 2012 - 06:58 PM
Wannabe


Joined: Aug 26, 2008
Posts: 66
Location: Montreal, Canada

I've made an encoder recently for a dc motor on an AVR. It is usually fairly straight forward to implement especially if your signal is nice enough to be read with a digital pin. My main suggestion would be to hook up your encoder to an oscilloscope and see what kind of output it produces to make sure there aren't false positives and that the signal is clean.
 
 View user's profile Send private message  
Reply with quote Back to top
kameleon89
PostPosted: Feb 19, 2012 - 04:06 PM
Newbie


Joined: Feb 15, 2012
Posts: 5


It kinda works, I managed to calculate speed using the "p-method", counting the impulses during a time interval and when the timer makes an interrupt (CTC mode), speed is calculated.

The problem now is the LCD. It should be HD44780 based, and I used the same lib like on the lectures, and I wrote the program just like the examples we were given, but the LCD displays nothing. In fact, when I connect it on one of the I/O ports, the LED that I used to confirm that the speed measurement works doesn't work anymore.

I even tried changing the program and making the led light up when it catches an INT0 interrupt, but not even that worked with the LCD connected. I don't understand what I'm missing here.

EDIT: Just to add, I'm using Fleury's code for using the LCD with ATMega, and working in 4-bit mode.
 
 View user's profile Send private message  
Reply with quote Back to top
bobgardner
PostPosted: Feb 19, 2012 - 04:32 PM
10k+ Postman


Joined: Sep 04, 2002
Posts: 21257
Location: Orlando Florida

The E pulse to the lcd needs to be 500ns wide. A 16MHz AVR has a 62ns clock. So you set E hi, do 8 nops, set E low. This is different if the AVR clock speed is different.

_________________
Imagecraft compiler user
 
 View user's profile Send private message Send e-mail Visit poster's website 
Reply with quote Back to top
kameleon89
PostPosted: Feb 19, 2012 - 05:34 PM
Newbie


Joined: Feb 15, 2012
Posts: 5


It may be because of the contrast, when I try putting 5V on the 3rd pin the screen is totally blank, and when I connect it to GND, the first line fills with squares and the second line is blank.

I've also tried connecting it to 5V with a 10k resistor in between, but same as when the resistor is not there.

You mean the signal on the Enable pin of the LCD? I read something elsewhere about the differences in baud rate, but I didn't understand that very well. The ATMega16 I use has 7.3 MHz clock.
Besides, if I'm using a complete program for the lcd (Fleury), it should take care of such things, right?
 
 View user's profile Send private message  
Reply with quote Back to top
bobgardner
PostPosted: Feb 19, 2012 - 07:05 PM
10k+ Postman


Joined: Sep 04, 2002
Posts: 21257
Location: Orlando Florida

Try a pot from 5V to gnd, run the wiper to the contrast line. When the black boxes fade out, the characters under them should magically appear. As for using an existing program, yes it should work if nothing changes. If you have a different AVR with different register names, running at a different clock speed, and oh by the way, I had to move all the pins around because the ones that the example used were already used on my board, then there might be a problem.

_________________
Imagecraft compiler user
 
 View user's profile Send private message Send e-mail Visit poster's website 
Reply with quote Back to top
kameleon89
PostPosted: Feb 19, 2012 - 09:51 PM
Newbie


Joined: Feb 15, 2012
Posts: 5


Yeah, I asked some coleagues as well, they say a pot is essential to see anything on the display, so I guess that should work. I'll buy one tomorrow. All the settings in the header file are correct, checked it a few times.

However, what troubles me even more, is that the code I have previously written to see how the speed calculation works is no longer functional. It seems as though the INT0 external interrupt doesn't work while I have the LCD connected. I don't understand why, I have tried connecting it both on PORTB and PORTA, and the INT0 pin is on PORTD.
I mean, it might be something else, but when a LED that works when it's activated in the main program doesn't light up when activated from the interrupt subroutine, my guess would be that somehow the interrupt doesn't work...
 
 View user's profile Send private message  
Reply with quote Back to top
bobgardner
PostPosted: Feb 19, 2012 - 09:57 PM
10k+ Postman


Joined: Sep 04, 2002
Posts: 21257
Location: Orlando Florida

I think that these type of problems are proof that there is a devil put here to mess with us. I know all the agnostics and atheists will claim that there is no God, but I betcha by golly that they've seen the electronic devil's handiwork trying to sabotage them. Amen.

_________________
Imagecraft compiler user
 
 View user's profile Send private message Send e-mail Visit poster's website 
Reply with quote Back to top
Display posts from previous:     
Jump to:  
All times are GMT + 1 Hour
Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Powered by PNphpBB2 © 2003-2006 The PNphpBB Group
Credits