Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
I have a ADC result that I am converting to a float. I want to display on a 4 digit 7 segment display via a BCD decoder. How do I break the float into 100’s, 10’s, 1’s and 10th’s to convert to BCD for the decoder
Not to be too picky, but I think maybe your calculator needs a new battery.So if you measure 330 counts, you'd calculate 5 * 330 / 1023 = 1.651 volts. However,
You can also say 5000 * 330 / 1023 = 1651
I have a ADC result that I am converting to a float. I want to display on a 4 digit 7 segment display via a BCD decoder. How do I break the float into 100’s, 10’s, 1’s and 10th’s to convert to BCD for the decoder
nsaspook not sure I understand your point
#include <stdio.h>
int main()
{
int n = 7569;
int th,h,t,u; // Thousands,hundreds,tens,units
u=n%10;
t=(n/10)%10;
h=(n/100)%10;
th=n/1000;
printf("Thousands = %d , Hundreds = %d , Tens = %d , Units = %d\n",th,h,t,u);
return 0;
}
Nigel Goodwin & gophert in am using the ADC to read temperature from a thermistor to a tenth of a degree. Nigel Goodwin I'm using c in MPLab
LCD_charD(Thou);
LCD_charD(Hund);
LCD_charD(Tens);
LCD_char(46); //decimal point
LCD_charD(Ones);
void LCD_charD(unsigned char ch)
{
ch+=0x30;
LCD_char(ch); // convert to ascii
}
/*
* assuming the value is to be converted to 5V
* with 1 decimal place
*/
void showADC(uint16_t dat){
uint32_t total;
uint8_t tenths,units,tens,hund;
total=dat*5000; //multiply by millivolts
total>>=10; //divide by ADC resolution (1024)
tenths=total%10+0x30;
total/=10;
units=total%10+0x30;
total/=10;
tens=total%10+0x30;
total/=10;
hund=total+0x30;
}
/*
* assuming the value is to be converted to 5V
* with 1 decimal place
*/
void showADC(uint16_t dat){
uint32_t total;
unit16_t totint;
uint8_t tenths,units,tens,hund;
total=dat*5000; //multiply by millivolts
totint = total >> 10; //divide by ADC resolution (1024)
tenths=totint%10+0x30;
totint/=10;
units=totint%10+0x30;
totint/=10;
tens=totint%10+0x30;
totint/=10;
hund=totint+0x30;
}
uint32_t total;
uint16_t dat;
total=dat*5000; //multiply by millivolts
total=dat*5000ul; //multiply by millivolts
double TempConversion (int TempResult)
{
double Temp;
Temp = log(10000.0*((1024.0/TempResult-1)));
// =log(10000.0/(1024.0/RawADC-1)) // for pull-up configuration
Temp = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * Temp * Temp ))* Temp );
Temp -= 273.15; // Convert Kelvin to Celcius
return Temp;
}
rjenkinsgb & Pommie thanks for your information but I am reading the ADC through a thermistor for temperature, so not sure how to apply it.
C:double TempConversion (int TempResult) { double Temp; Temp = log(10000.0*((1024.0/TempResult-1))); // =log(10000.0/(1024.0/RawADC-1)) // for pull-up configuration Temp = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * Temp * Temp ))* Temp ); Temp -= 273.15; // Convert Kelvin to Celcius return Temp; }
I am taking the result and type casting to a float to display remotely on a LCD and locally on a four digit 7 segment(that I'm driving w/ a BCD decoder) display to the tenth of a degree.