Hello guy, I'm trying to interface hx711 adc with pi16f877a.. I've found the reference C program in the datasheet for hx711.. from that i was able to get raw readings from the hx711, i am using mikroC complier. my question is how can i get this readings to represent a weight.. is there any formula..? and i guess the initial raw reading under no load is the OFFSET value which you subtract from next readings to balance the zero position.. but when i do that the readings fluctuate here and there and will not zero the readings.. but when i connect the same setup to arduino.. readings are normal and most importantly the no load value stays at zero without fluctuating... what am i missing?
C:
#define LOW 0
#define HIGH 1
#define INPUT 1
#define OUTPUT 0
sbit HX711_SCLK at RB5_bit;
sbit HX711_DOUT at RB4_bit;
sbit HX711_SCLK_Direction at TRISB5_bit;
sbit HX711_DOUT_Direction at TRISB4_bit;
sbit LCD_RS at RD2_bit;
sbit LCD_EN at RD3_bit;
sbit LCD_D4 at RD4_bit;
sbit LCD_D5 at RD5_bit;
sbit LCD_D6 at RD6_bit;
sbit LCD_D7 at RD7_bit;
sbit LCD_RS_Direction at TRISD2_bit;
sbit LCD_EN_Direction at TRISD3_bit;
sbit LCD_D4_Direction at TRISD4_bit;
sbit LCD_D5_Direction at TRISD5_bit;
sbit LCD_D6_Direction at TRISD6_bit;
sbit LCD_D7_Direction at TRISD7_bit;
char txt[10];
float read1 = 0;
float offset = 0;
float gram = 0;
float val1;
float val2;
int k;
unsigned long Read_HX711() {
unsigned long count = 0;
unsigned char i; //, highest = 0, higher = 0, hi = 0, lo = 0;
HX711_DOUT_Direction = OUTPUT;
HX711_SCLK_Direction = OUTPUT;
HX711_DOUT = 1;
HX711_SCLK = 0;
HX711_DOUT_Direction = INPUT;
while(HX711_DOUT);
for(i = 0; i < 24; i++) { // gain 128
HX711_SCLK = 1;
count <<= 1;
HX711_SCLK = 0;
if(HX711_DOUT)count++;
}
HX711_SCLK = 1;
count ^= 0x800000;
HX711_SCLK = 0;
return(count);
}
unsigned long readAverage(void) {
double sum = 0;
for (k = 0; k < 10; k++) {
sum = sum + Read_HX711();
}
sum = sum /10;
return sum;
}
void main(void) {
LCD_Init();
LCD_Cmd(_LCD_CURSOR_OFF);
LCD_Cmd(_LCD_CLEAR);
offset = readAverage();
while (1) {
read1 = readAverage(); // this is my try for the initial readings to stay at zero
if (offset >= read1) {
val1 = (offset - read1);
gram = val1;
} else {
val2 = (read1 - offset);
gram = val2;
}//////////////////////////////////////////////////////////////////////////////
floatToStr_FixLen(gram, txt,6);
LCD_Out(1,4,txt);
//gram value is fluctuating
}
}