how would i go about scaling an adc value to represent a voltage value?
im back at playing with bemf for one of my projects and need to scale the read adc value to voltage and also apply that scaling to pwm range to hopefully make pwm adjustments better for changes to hpwm to maintain a desired speed as loads change on the motor.
i am using 12.6v max input for the motor and have resistor divider on h bridge going back to pic adc but now the part of working out how i would scale the actual vs desired voltage eludes me completely,especially as floating point is not an option ( and big maths is not my strongpoint :P )
tony
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Your resistor divider needs to limit 12.6v to 5v. When you have 12.6v (5v on the ADC pin
of the PIC) a 10 bit ADC will give a value of 1023, 6.3v will give 511 etc.
The PWM functions in GCB take values of 0-255, therefore just divide the ADC result by 4 to get a value for the PWM function.
I think...
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
hi peter,
thank you that should definately help with this project, i have my resistor divider from the h bridge all set up in place so i will have a mess around on paper with the conversions and see how i go on with that.
tony
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
If you are sampling off a motor, then it might be wise to stick a reverse biased diode from your ADC pin up to VCC to protect the Input. Inductive loads like motors can and do produce very high spikes and the resistance of your divider may not be enough to protect the input. Whilst they do have protection, it may not be sufficient, which is where the diode may help shunt anythign higher than VCC. Ensure you have good bypassing also.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
@ Sleepwalker3 thanks for the additional info, thankfully im still playing with this on the breadboard for the time being so once the code additions have been made and calculate good ill mod the circuit setup ready to test it.
last time i briefly played with the crude setup it was pretty quick to respond but now im getting their with the calcs for voltage and pwm adjustments based on the feedback it should be pretty snappy to respond lol, might have to add some software conditioning to make sure i dont destroy the gearset on the motor lol
tony
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
thanks chris, that will no doubt make for some interesting and usefull reading.
so far today i have been able to grab some time and sit down and do some intitial calculations for voltage scaling and also rough draft theory of implementing it appropriately to the pwm output for some swift changes to account for the load variations and make sure it adjusts itself in what should be a very quick response to maintain the desired output :)
im just back at the pc now to start going over the additions to add to the code and hopefully test later tonight or tomorrow.
so far my calculations on paper armed with calculator and ideas theoretically seem valid and should be much improved over the rough draft version i played around with last time.
once i have it implemented and working ill post back with some more info.
tony
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
how would i go about scaling an adc value to represent a voltage value?
im back at playing with bemf for one of my projects and need to scale the read adc value to voltage and also apply that scaling to pwm range to hopefully make pwm adjustments better for changes to hpwm to maintain a desired speed as loads change on the motor.
i am using 12.6v max input for the motor and have resistor divider on h bridge going back to pic adc but now the part of working out how i would scale the actual vs desired voltage eludes me completely,especially as floating point is not an option ( and big maths is not my strongpoint :P )
tony
Does this help?
https://learn.sparkfun.com/tutorials/analog-to-digital-conversion/relating-adc-value-to-voltage
Your resistor divider needs to limit 12.6v to 5v. When you have 12.6v (5v on the ADC pin
of the PIC) a 10 bit ADC will give a value of 1023, 6.3v will give 511 etc.
The PWM functions in GCB take values of 0-255, therefore just divide the ADC result by 4 to get a value for the PWM function.
I think...
hi peter,
thank you that should definately help with this project, i have my resistor divider from the h bridge all set up in place so i will have a mess around on paper with the conversions and see how i go on with that.
tony
If you are sampling off a motor, then it might be wise to stick a reverse biased diode from your ADC pin up to VCC to protect the Input. Inductive loads like motors can and do produce very high spikes and the resistance of your divider may not be enough to protect the input. Whilst they do have protection, it may not be sufficient, which is where the diode may help shunt anythign higher than VCC. Ensure you have good bypassing also.
@ Sleepwalker3 thanks for the additional info, thankfully im still playing with this on the breadboard for the time being so once the code additions have been made and calculate good ill mod the circuit setup ready to test it.
last time i briefly played with the crude setup it was pretty quick to respond but now im getting their with the calcs for voltage and pwm adjustments based on the feedback it should be pretty snappy to respond lol, might have to add some software conditioning to make sure i dont destroy the gearset on the motor lol
tony
You may find this of use, or at least a good read.
thanks chris, that will no doubt make for some interesting and usefull reading.
so far today i have been able to grab some time and sit down and do some intitial calculations for voltage scaling and also rough draft theory of implementing it appropriately to the pwm output for some swift changes to account for the load variations and make sure it adjusts itself in what should be a very quick response to maintain the desired output :)
im just back at the pc now to start going over the additions to add to the code and hopefully test later tonight or tomorrow.
so far my calculations on paper armed with calculator and ideas theoretically seem valid and should be much improved over the rough draft version i played around with last time.
once i have it implemented and working ill post back with some more info.
tony
A small value cap from the input to processor ground might also be in order, as the motor is likely to give lots of noise.
Scaling one range of numbers to another range of numbers can be done with the following mathematical formula.
result = (x - input_min) * (output_max - output_min) / (input_max - input_min) + output_min
For Example: We need a 10-bit ADC (0 to 1023) to represent a voltage from 0.00 to 5.00
Result = (ADC_Val - 0) * (500 - 0) / (1023 - 0) + 0 .. or
Result = ADC_Val * 500 / 1023
To verify, assume that the ADC value is 512. This should result in a value of ~250 or 2.50 Volts (add decimal point later)
512 * 500 / 1023 = 250 (rounded)
So if an ADC range of 0-1023 is to represent a voltage range of 0.00 to 12.6 then
Voltage = ReadADC10 * 1260 / 1023
To prevent overflow/errors the numbers should be declared as LONG integers
This is the same formula used by the Arduino MAP function.
Last edit: William Roth 2016-09-26