View Single Post
Old 01-14-2021, 05:00 PM   #45
Second Series
Registered User
 
Second Series's Avatar
 
Join Date: May 2015
Location: Tukwila Washington
Posts: 373
Re: Mechanical speedometer drive solution

I’m still working on this and making progress. I have been working on the code for my rebuilt funky speedometer, and it seems to be working well enough. I asked for advise on an electronics forum about connecting to an automobile. I noticed my truck produces about 14v for the 12v line. I had always checked voltage with the engine off, or with a test light, so this is new information for me although I am not surprised. I asked about using a voltage regulator because my code is based on running the motor on 12v. I was informed that a 12v regulator needs at least 14.4v to function properly, but an LDO regulator would work in this application. LDO=Low Drop Out. I located a 12v 3A LDO regulator, ordered a few and received them it in the mail. Next step is to wire it in and connect to my truck. This week I tried searching for more information about PID code for a speedometer and found this post:
http://ka7oei.blogspot.com/2019/01/e...eter-with.html
I have read several articles about PID, but this one basically spells it out enough for me to understand. I tried to implement some code in my sketch yesterday, but it wasn’t happening. I thought about it, and today rearranged some things and it works.
PID
error = desired speed – actual speed
integral = integral + (error * ITIME)
derivative = (error – error_prior)/ITIME)
output = Kp*error + Ki*integral + Kd*derivative + BIAS
error_prior = error

Desired speed is the motor speed determined by the 2000ppm frequency multiplied by the torque curve equation results.
Actual speed is the optical disk speed determined by detecting disk pulses each second aka frq2. The value of frq2 is in Hz. There are 64 holes in the optical disk. diskRPS is determined by dividing frq2 by 64.
Let’s convert the 2Kppm value to RPS. Call it motHz For motor RPS.
Take the known 2Kppm values and the diskRPS and create a chart. Add a trendline to the chart to get an equation. Plug the 2Kppm values into the equation to get the motHz. motHz is close to diskRPM, but not exact.


This dataset uses values for 22mph to 80mph. The 2kppm is a set range for all vehicles. The optical disk readings are the average of a range for each data point. I set the code to output the count from the optical disk and the readings fluctuated so I recorded an average.
Take the motHz and the recorded PWM values to create a graph, insert trendline to get the equation. Plug motHz values into the equation to get the PWM. Use this equation in the code.


y = (0.00004*(x^2)-(0.0022*x)+60.708)
#define val20 (pow(output,2))
Drive = (0.00004*(val20)-(0.0022*output)+60.708)
The PID code works well, really smooth, and it works on the low end. I still need to tune it and figure out what is happening, but so far I like what I see. I’ll strip most of my code out, basically start over again. I think it will be much more simple, and may not matter what voltage is supplying the motor.
Attached Images
  
__________________
'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