J'ai un probleme de programmation avec la jauge HX711 et le PIC18F45K22.
J'utilise le meme setup que sur ce lien :
https://www.bitstoc.com/wp-content/uplo ... ide-v1.pdf
J'ai essayer avec un module arduino Uno tel qu'indiqué et ca fonctionne tres bien.
J'utilise le même HX711+jauge mais avec un PIC. mais la valeur varie énormément.
je post mon code ci-dessous. Deplus,je prends un échantillon central de 15 sur 25 et je fait la moyenne de ses 15 valeurs.
Mes valeurs ne sont jamais stable.
Une personne a deja programmé un HX711 ? avec PIC ?
Code : Tout sélectionner
sbit ADSK at RD2_bit; // set PIN clock to RD2
sbit ADDO at RD3_bit; // set PIN data to RD3
sbit ADSK_Direction at TRISD.B2;
sbit ADDO_Direction at TRISD.B3;
char *txt = "000.0000";
int i, j;
long int data_average;
unsigned long count;
long int array[25] ;
long int temp;
unsigned long Poids;
unsigned long decimals;
void bubble_sort() {
for(i = 0; i<25; i++) {
for( j = i+1; j<25; j++)
{
temp =0;
if(array[j] < array[i]) {
temp = array[i];
array[i] = array[j];
array[j] = temp;
}
}
}
} // end bubble sort
float HX711_Get_Weight() {
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);
data_average = 0;
for(j = 0; j < 25; j++) {
TRISD = 0b10110010; //0 = Output,
ADDO = 1;
ADSK = 0;
TRISD = 0b10111010; //0 = Output, 1 = Input RD3
while(ADDO ) ;
//wait until ADDO is zero
count = 0;
Poids = 0x800000;
for(i = 0; i < 25; i++)
{
Delay_us(10);
ADSK = 1;
Delay_us(10);
ADSK = 0;
if(ADDO==1) count = count + Poids ;
// if(ADDO==0) count = count ; // dont really need this line
Poids = Poids >> 1;
} // end for loop
array[j] = count;
Delay_ms(20);
if (count > 0xFFFFFF)
{
LCD_Cmd(_LCD_CURSOR_OFF);
LCD_Cmd(_LCD_CLEAR);
LongWordToStr(count, txt);
Lcd_Out(1, 1, "Out of range");
Lcd_Out(2,1,txt);
Delay_ms(800);
}
bubble_sort();
temp =0;
for(j = 10; j < 15; j++)
{
temp = temp + array[j];
}
temp = temp /5 ; // divide to get average
temp = temp - 86840; // TAR the value
temp = temp / 7 ; // divide by 7.7 for the next two lines*/
temp = temp * 100;
temp = temp / 778 ; // divide by 778
return temp ;
} // end main 


hors temp est un long int !
Ah que ouais ....