I'm novice with C programming and i need to some help to do some calculation written in C code.
I'm using an acceleration module MMA7260Q that delivers a voltage depending the gravity measurement.
I would like to display how many 'G' my module measures :
I'm able to display the voltage issued from Z axis with the following code : ( tested ok )
Code: Select all
// Added for AN reading :
unsigned char ch;
long tlong;
unsigned int z_read;
...
Lcd_Out(2,1,("Z:"));
z_read = ADC_read(1); // get ADC value from 1st channel ( RA0 )
IntToStr(z_read, val_adc);
tlong = (long)z_read * 5000; // convert adc reading to milivolts ( 5000 if Pic Vcc = 5.00V 4970 for Pic Vcc = 4.97V )
tlong = tlong / 1023; // 0..1023 -> 0-5000mV
ch = (tlong / 1000); // extract volts digit (* 4 is resistors divider bridge ratio)
LCD_Chr(2,3,48+ch); // write ASCII digit at 4nd row, 16th column ( ecrit la valeur mesurée à partir de la 16ème colonne )
LCD_Chr_CP('.');
ch = ((tlong / 100) % 10); // extract 0.1 volts digit (* 4 is resistors divider bridge ratio)
LCD_Chr_CP(48+ch); // write ASCII digit at cursor point
ch = (tlong / 10) % 10; // extract 0.01 volts digit
LCD_Chr_CP(48+ch); // write ASCII digit at cursor point
For now, i would like to display how many 'G' this voltage represents but i don't know how to do the calculations
In normal condition ( sensor not moved ) voltage is 2.54V this represents earth gravity = ' 1G '
when sensor records +1G, it adds +0.8V , when sensor records -1G it loose -0.8V to reference voltage : 2.54V
i would like to run a loop and display on a LCD how many 'G' (3 digits) the sensor reads.
ie : G = 1.00 or G = 1.55
If someone already made a project with that sensor or able to help to write the calculations i will really appreciate it .
Best Regards,