Hello everyone. It's been a while since my last post. Many of you may remember my tachometer project that you AVR Freaks were so helpful with me completing:
https://www.avrfreaks.net/forum/my-digital-tachometer-putting-it-all-together
Since then, I've been busy with other projects; I made three custom tachometers (as noted at the end of the above thread), and have been converting the machine tools in my machine shop to use VFDs (Variable Frequency Drives). This involved making new drive mechanics and removing the mechanical vari-speed drive. Additionally, it gave me an application for the afore mentioned tachometer. I made a large digital display for one.... I've also been setting up a small in-house anodizing line.
I now have a new "micro" project... well... maybe resurrecting an older one:
https://www.avrfreaks.net/forum/syncronizing-2-rc-airplane-motors
I'm making a device that uses two motors with offset weights to cause vibration. This device is battery powered and uses BLDC motors normally used for R/C airplanes. To create the desired vibration, the motors counter-rotate and they need to be synchronized with the weights 180* out of phase. For the proof-of-concept prototype, I'm using an AVR with generic ESCs and controlling the motor speed the same way a hobby servo is controlled (PWM). A potentiometer is used so the operator can select the nominal RPM of the system.
I have some parts of the system working already.
I'm using an ATtiny261. I have the ADC routine working (8 bit) and can easily read the potentiometer position. Using this ADC reading, the PWM (for hobby servo control) is altered. I don't yet have the ESCs, so I am testing with a hobby servo. The PWM for two separate servos works great. The servo (or ESC) PWM is controlled from Timer1. Since it is an 8 bit timer, I used some tricks with the overflow interrupt to get decent resolution to the pulse width.
The next step is to determine how to sense RPM and angular position, and what strategy to use to measure them. I have some ideas and some questions.
I plan to use an opto-interrupter or hall sensor to get a once-per-rev pulse at the rotational position of the offset weight of EACH motor. Also, it's okay to take a second or two to get the motors synced at startup. Plus it's okay to have a tolerance in the phase angle of plus or minus 10 to 15 degrees.
One idea is to use the Timer0 Input Capture to measure the time from motor1 interrupt to motor2 interrupt, and then from motor2 to motor1. The object is to make the times equal each other.
Another idea is to use external INT0 and INT1 to time each motor interrupt and go from there.
The questions I have are mostly in regard to Input Capture.
First, what happens if the timer overflows between captures?
Second, since I'll be using Timer0 in 16 bit mode, do I need to deal with combining the two bytes or does the compiler take care of that for me?
It seems that using separate interrupts (INT0, INT1) for each motor makes it easier to know which motor is ahead of the other than using Input Capture (since there is only one). However, INT0 & INT2 have more overhead. Oh, this reminds me of another question.
Third, the data sheet says that Input Capture can be triggered by the ICP0 pin or alternatively, AC0. Could these two different inputs be used to help distinguish between which motor triggered the interrupt?
Do any of you have comments about one or both approaches... pros/cons....
Thanks!
Cris