counting RPM by Incremental encoder using visual C++

D

Thread Starter

danny

How to write a program by using C++ for getting the position control by showing the Speed RPM, and Position for incremental encoder.
 
R

Robert Scott

This is tricky. It is no problem getting incremental encoder readings by using the C library that comes with the various encoder boards.
The problem is that to calculate RPM you need to know WHEN the encoder reading was taken. If your C/C++ program is running under Windows,
it is subject to multi-tasking delays. If you read the system clock, then read the encoder, there could be a significantly large amount of
time between those two reads. You could read the system time both before and after the encoder reading and thereby have a range of times
that could correspond to the encoder reading. Another method is to write both the encoder sampling and the system clock sampling in a
device driver (a VxD in Windows 98/ME or a kernel mode device driver in Windows 2000/NT/XP). This is not a trivial task. Finally, you can always trade off precision for response time. That is, if you increase the time between two encoder reads, then you get better RPM precision because the system induced uncertainty in the timing measurement is a smaller fraction of the overall time between encoder reads. However, this will also worsen your response time, since it now takes longer to get an RPM reading. You must look closely at your application and decide how slowly you can afford to make the RPM calculations. Then use that time span for your encoder samples. If you do use very long time samples, you may have to consider the possibility of overflow in the encoder counting board. This can be handled by
intermediate encoder reads that watch for overflow and maintain a software extension to the encoder counter registers.

I have implemented this particular function a number of times in various settings, so if you need specific advice, contact me directly
([email protected]).
 
Hi, i am using VB V6 and the UART of the microcontroller (AT90S8515), in order to read two incremental encoders.
if someone wants the assambler and vb code. Feel free to contact me.
jose juan lara
[email protected]
 
Top