|
|
View previous topic :: View next topic |
Author |
Message |
Faisal Guest
|
how to control the speed of a DC motor using a photo sensor? |
Posted: Tue May 31, 2005 12:41 pm |
|
|
can anyone help in how to code a circuit that should be controlling a DC motor using a Transmissive Photosensors (Photo lnterrupters) same one used in a mouse...?
i had it working using a photoreflector on LABWINDOWS, i had to use a PID controller to it , i am really new to PIC programming but i think the concepts are the same ..
i am using a PIC 16f877A and the CCS prototyping board rev. 7
is there any example code that someone can provide me ...
thank you |
|
|
rwyoung
Joined: 12 Nov 2003 Posts: 563 Location: Lawrence, KS USA
|
|
Posted: Tue May 31, 2005 1:38 pm |
|
|
Search the forum for "PID". Will give a screen full of hits, most of which contain some small bit of information or a link to another page.
There is a nice overview article in Embedded Engineering, sometime in 2000. "PID without a PhD" or something like that. It has code (with a small bug) that will compile in CCS (after fixing the syntax bug). Not terribly efficient as it is done with floating point but it does work.
You will probably be using your interrupter as a tachometer so there is another search term for the forum. _________________ Rob Young
The Screw-Up Fairy may just visit you but he has crashed on my couch for the last month! |
|
|
sseidman
Joined: 14 Mar 2005 Posts: 159
|
|
Posted: Tue May 31, 2005 2:48 pm |
|
|
Is this a quadrature device?? I would assume so, or you have no way of knowing direction (unless your system only goes in one direction. We also need to know if you're trying to control velocity or position.
If it's quadrature (there would be two signals), you can use the inputs to trigger two timers in counter mode to keep track of current position (search for quadrature), and you're not too interested in time if you're controlling position, so lond as whatever control algorithm you're using is driven at a constant rate via a timer interrupt.
If things are moving slow enough, you shouldn't have any problems. If you search my profile, look at some of my first posts for a general description of this approach. Of course, it didn't work for me-- I think because things were just happening so quickly I was losing counts, but I never confirmed the problem-- I just moved to an 18F2331, which specializes in quadrature, and that dealt with the whole thing. A code snippet of this is also in my profile history. If your compiler supports the 18F series, this microcontroller can make your life pretty easy (and then complicate it again with its beefy, complex, PWM module).
If it's not quadrature, the approach would be similar, only you need to know somehow what direction things are moving in to determine whether you need to increment or decrement your position count.
If you're doing velocity control, you can take the same approach, but you need to bring time into the equation. This shouldn't be a problem-- just divide the position counts since your last read (no need to keep a running total in this case) by the sampling interval to get velocity. Try to use integer division if you can.
I'd recommend starting with a "PI" controller instead of a "PID" controller, at least to start. If it controls well enough, you can stop. The "D" stands for derivative, and derivatives can be noisy. If you don't need it, leave it out.
"PID without a PhD" can be linked to from the author's (Tim Wescott's) page at http://www.wescottdesign.com/
Good Luck
Scott |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|