lerameur
Junior Member level 1
Hello,
I am using the PIC18F46K22 with MikroC language to program and read a HX711 IC.
I am not getting a steady output.
I added a loop (10x) to get an average, but still its fluctuating between 8453470 and 8427890.
Any help would be appreciated.
I am using the PIC18F46K22 with MikroC language to program and read a HX711 IC.
I am not getting a steady output.
I added a loop (10x) to get an average, but still its fluctuating between 8453470 and 8427890.
Any help would be appreciated.
C:
sbit ADSK at RD2_bit;
sbit ADDO at RD3_bit;
sbit ADSK_Direction at TRISD.B2;
sbit ADDO_Direction at TRISD.B3;
sbit LCD_RS at LATA5_bit;
sbit LCD_EN at LATA4_bit;
sbit LCD_D4 at LATA0_bit;
sbit LCD_D5 at LATA1_bit;
sbit LCD_D6 at LATA2_bit;
sbit LCD_D7 at LATA3_bit;
sbit LCD_RS_Direction at TRISA5_bit;
sbit LCD_EN_Direction at TRISA4_bit;
sbit LCD_D4_Direction at TRISA0_bit;
sbit LCD_D5_Direction at TRISA1_bit;
sbit LCD_D6_Direction at TRISA2_bit;
sbit LCD_D7_Direction at TRISA3_bit;
char txt;
char txt2;
int i, j;
unsigned long data_average;
unsigned long count;
void main(void) {
C1ON_bit = 0; // Disable comparators
C2ON_bit = 0;
ADCON1 |= 0x0F;
ADCON1 = 0b00000110; // all ADC ports digital
SLRCON = 0; // Configure all PORTS at the standard Slew Rate
////////////////////
VREFCON1=0; // vref off
VREFCON2=0; // vref off
PORTD = 0b00000000;
INTCON = 0b00000000; // disable all interrupts ...INT0IE: RB0/INT External Interrupt Enable bit
ANSELD = 0b11000000; // Configure all PORTS at the standard Slew Rate
LCD_Init();
LCD_Cmd(_LCD_CURSOR_OFF);
LCD_Cmd(_LCD_CLEAR);
while(1) {
data_average = 0;
for(j = 0; j < 10; j++) {
// data_average = data_average + data_average_new ;
TRISD = 0b10110010; //0 = Output,
ADDO = 1;
ADSK = 0;
TRISD = 0b10111010; //0 = Output, 1 = Input RD3
while(ADDO ) ;
//wait until ADDO is zero
count = 0;
for(i = 0; i < 15; i++) {
Delay_us(3);
ADSK = 1;
Delay_us(3);
ADSK = 0;
if(ADDO=1) count = count +1 ;
if(ADDO=0) count = count ; // dont really need this line
count = count << 1 ;
} // end for loop
ADSK = 1;
count = count ^ 0x800000;
ADSK = 0;
if (count > 0xFFFFFF)
{
LCD_Cmd(_LCD_CURSOR_OFF);
LCD_Cmd(_LCD_CLEAR);
lcd_out(1, 1, "Out of range");
LCD_Out(2,4,txt);
Delay_ms(200);
}
// } // end while loop
data_average = data_average + count;
} // end for loop j
//IntToStr(j, txt2);
data_average = data_average / 10;
LongToStr(data_average, txt);
LCD_Cmd(_LCD_CLEAR);
lcd_out(1, 1, "For loop:");
// LCD_Out(1,11,txt2);
LCD_Out(2,1,txt);
Delay_ms(600);
}
} // end main