View Single Post
Old 03-13-2020, 04:31 PM   #28
Second Series
Registered User
 
Second Series's Avatar
 
Join Date: May 2015
Location: Tukwila Washington
Posts: 373
Re: Mechanical speedometer drive solution

I keep meaning to post an update and have put it off three times now, so here is the progress:
I was able to get a consistent speed with the simple code for frequency input. The code for reading the optical disk is the same as the code for detecting input frequency, but I was having delay issues. I couldn’t find any examples of code with both frequency input and an optical disk. I read that using Interrupts is the way to go for reading an encoder, so I implemented the code, sharing timer resources. The results were way off, then I remembered reading something about Floating-point variables taking too much time. I set the variables as Integers, and now the motor speed is controlled by the input frequency, and the optical disk produces a clean output frequency.
The next step is to scale the output frequency from the optical disk to the input drive frequency. This action will turn the dc motor into a Servo motor. The input frequency will determine the speed of the motor, the encoder frequency will be used to keep the speed consistent. This should translate to meaning the speedometer needle will not flutter or bounce.
I have yet to connect the speedometer to any motor as this programming is getting deep. The speedometer will be a light load that will not change, so the motor speed shouldn’t be affected by the load. The motor speed might change after the motor gets hot, that is yet to be determined. The optical disk will help maintain a steady speed. I’m interested in using it to control the low end speed. I have read that speeds below 10mph can be problematic with the off-the-shelf products available. The motor needs to have a wide enough range for 0 to 90mph or higher, and be able to run slow. Using gears reduces the slow speed, but it also lowers the top speed.
The Arduino PWM is at a set frequency. The motor needs a minimum supply to start turning, that works out to be around 5mph. I’ll try to write some code that gets the motor spinning, but keeps it moving at a slower rpm. Basically, I’ll use the minimum PWM signal to get the motor spinning, and toggle the PWM off and on. If that doesn’t work, I’ll get into PFM(Pulse Frequency Modulation). That will require manipulating the registers of the microproccessor on the Arduino to change the clock speed. Reclocking through machine language. This will also alter the clock signal that is used to read the input frequency, and optical disk, so that will have to be compensated. Murky territory that I would prefer to avoid.

I have been struggling with the code, but making some progress. The timing for the Optical read <+.3%error with using Interrupts. The timing for the input frequency was greater than up to 20% with using interrupts, may be due to to frequency range of 1Hz to 60Hz. Polling the pin state yields <+.1%error for the timing of the input frequency, so I won’t use interrupts to read the input frequency.
The Optical disk has 64 holes, so the ratio between optical disk frequency and the input frequency works out to something like 50:1. I wasn’t seeing much servo action, the motor drive frequency is updated every second with the code, and the optical disk frequency is also updated every second. I’m using the arduino Serial Monitor on my pc to troubleshoot the code. The input frequency matches what the fuction generator is set at, 10Hz. The optical disk is fluctuating 414Hz. to 440Hz. That indicates the motor speed is fluctuating. I took about 10 samples at each input setting from 7Hz to 63Hz. I put all the data into a spreadsheet. Divide the optical disk frequency by 64 and get RPM of the motor. Then divide the input frequency by RPM to get the multiplier. There are 315 samples with a multiplier from 1.09 to 2.94, so Add all the multipliers and divide by 315 to get 1.39. Now I start the motor, and then divide the input frequency by 1.39 and multiply that by 64. This gives me the target frequency. Compare this target frequency to the optical disk frequency, and the drive signal adjusts up or down. I take more samples at each frequency, but the optical disk frequency is still fluctuating, maybe less than before, and the motor can start at a slightly slower speed. So some progress.
I thought a hydraulic motor might be a better solution. Run a couple lines from the power steering up under the dash, control the amount of pressure spinning the drive. The slow speeds wouldn’t be a problem. Not finding any small hydraulic motors available, or economical. I did find some miniature RC excavators, that looks like an expensive hobby. I also found mention of PID controllers(Proportional/Integral/Derivative). So it looks like I am already building a PID controller, just didn’t know it. I’ll keep hacking away on this.
Today, I decided to work on the slow speed. I turned off the PID part of the code. Using the optical count, a delay can be introduced at regular intervals. I tried a bunch of different combinations. With a delay of 30 microseconds every hole, the motor rotates at .308Hz, or 1.1mph. In effect it is a stepper motor. Now I’ll have to develop this slow speed code and incorporate it into the PID.
__________________
'47 Panel to '88 K2500 Frame Swap
Mechanical Speedometer Drive Solution
1947.2 1 ton Chevy Panel
1955.2 Chevy 6700 Bus/RV
1990 Chevy K1500
Second Series is offline   Reply With Quote