L'exemple de code est écrit en C. Peu importe que le processeur cible soit Microchip PIC ou Atmel AVR, sauf pour les dépendances liées au matériel.
[/CITATION]
puis-je l'implémenter sous mikroC ?
L'exemple de code est écrit en C. Peu importe que le processeur cible soit Microchip PIC ou Atmel AVR, sauf pour les dépendances liées au matériel.
[/CITATION]
puis-je l'implémenter sous mikroC ?
Can't open include file "avr/io.h" same thing for <avr/interrupt.h>If mikroC doesn't recognize the syntax it would give you a compiler error.
What is the error?
That is because the files are missing.Can't open include file "avr/io.h" same thing for <avr/interrupt.h>
On mikroC not a specific file . It's like the code C in the post #1 . Please are you ok with my code ?That is because the files are missing.
Look at your code and see what needs to be defined for the PIC processor.
I don't usually spend time trying to trouble-shoot user's code. This is something that you have to learn to do yourself.On mikroC not a specific file . It's like the code C in the post #1 . Please are you ok with my code ?
#define _XTAL_FREQ 20000000
#define DT_PIN RB1_bit
#define SCK_PIN RB0_bit
#define DT_TRIS TRISB1_bit
#define SCK_TRIS TRISB0_bit
long offset=0;
float scale =1;
float known_weight=1000;
void init_hx711(void);
long read_hx711(void);
void tare(void);
void calibrate(float known_weight);
float get_weight(void);
void main()
{
UART1_Init(9600);
delay_ms(100);
DT_TRIS=1;
SCK_TRIS=0;
init_hx711();
calibrate(known_weight);
tare();
//calibrate(float known_weight);
while (1)
{
float weight = get_weight();
char weight_str[10];
char LuRaw[10];
UART1_Write_Text("Raw value: ");
FloatToStr(read_hx711(), LuRaw);
UART1_Write_Text(" g\r\n");
UART1_Write_Text("calibration");
UART1_Write_Text("Poids: ");
FloatToStr(weight, weight_str);
UART1_Write_Text(" g\r\n");
delay_ms(1000);
}
}
void init_hx711(void)
{
SCK_PIN=0;
}
long read_hx711(void)
{ int i;
long count =0;
while (DT_PIN);
for(i =0; i<24; i++)
{ SCK_PIN=1;
delay_us(1);
count=count <<1;
SCK_PIN=0;
delay_us(1);
if(DT_PIN) count++;
}
SCK_PIN =1;
delay_us(1);
SCK_PIN=0;
delay_us(1);
count^=0x800000;
return count;
}
void tare (void)
{
long sum=0;
int i;
for(i =0;i<10;i++)
{
sum+=read_hx711();
delay_ms(100);
}
}
void calibrate( float known_weight){
long raw_value= read_hx711()-offset;
scale= raw_value/known_weight;
}
float get_weight(void)
{
long raw_value= read_hx711() - offset;
return raw_value/scale;
}
I completely agree with you. and your approach I did it but so far no resultsI don't usually spend time trying to trouble-shoot user's code. This is something that you have to learn to do yourself.
Try to start simple and test one portion at a time.
C:#define _XTAL_FREQ 20000000 #define DT_PIN RB1_bit #define SCK_PIN RB0_bit #define DT_TRIS TRISB1_bit #define SCK_TRIS TRISB0_bit long offset=0; float scale =1; float known_weight=1000; void init_hx711(void); long read_hx711(void); void tare(void); void calibrate(float known_weight); float get_weight(void); void main() { UART1_Init(9600); delay_ms(100); DT_TRIS=1; SCK_TRIS=0; init_hx711(); calibrate(known_weight); tare(); //calibrate(float known_weight); while (1) { float weight = get_weight(); char weight_str[10]; char LuRaw[10]; UART1_Write_Text("Raw value: "); FloatToStr(read_hx711(), LuRaw); UART1_Write_Text(" g\r\n"); UART1_Write_Text("calibration"); UART1_Write_Text("Poids: "); FloatToStr(weight, weight_str); UART1_Write_Text(" g\r\n"); delay_ms(1000); } } void init_hx711(void) { SCK_PIN=0; } long read_hx711(void) { int i; long count =0; while (DT_PIN); for(i =0; i<24; i++) { SCK_PIN=1; delay_us(1); count=count <<1; SCK_PIN=0; delay_us(1); if(DT_PIN) count++; } SCK_PIN =1; delay_us(1); SCK_PIN=0; delay_us(1); count^=0x800000; return count; } void tare (void) { long sum=0; int i; for(i =0;i<10;i++) { sum+=read_hx711(); delay_ms(100); } } void calibrate( float known_weight){ long raw_value= read_hx711()-offset; scale= raw_value/known_weight; } float get_weight(void) { long raw_value= read_hx711() - offset; return raw_value/scale; }
FloatToStr(read_hx711(), LuRaw);
LongToStr(read_hx711(), LuRaw);
UART1_Write_Text(LuRaw);
thank you for your replyIt didn't register yesterday, but
Is not going to return a valid number. From what I could find on my quick look FloatToStr() expects an IEE754 compliant floating point number which is not the same as a 24 bit number. You need a bit more math to make a floating point number from the result.Code:FloatToStr(read_hx711(), LuRaw);
The function also does not in anyway print the result of the function to UART. You are missing that step entirely. Add something like
Other than that your code seams right. The scope images are questionable, but I am wondering if you have the timing set correctly. Maybe a shorter window or faster sample rate will produce something that looks like what you expect. If not then the delay_ms() is not working correctly. Unfortunately my understanding of C with PICs is pretty weak so I am not sure where to go with that. My language of choice with PICs is assembly.Code:LongToStr(read_hx711(), LuRaw); UART1_Write_Text(LuRaw);
| Thread starter | Similar threads | Forum | Replies | Date |
|---|---|---|---|---|
| J | 4x full-bridge or 4x half-bridge load cells to one HX711 | Sensor Design & Implementation | 1 | |
| V | Hx711 with pic16f877A ..#2 | Microcontrollers | 1 | |
| I | Help in designing HX711 circuit | General Electronics Chat | 0 | |
| M | Indicateur numérique de pesage | Microcontrollers | 4 | |
|
|
Hx711 interfacing with PIC16F877A | Microcontrollers | 2 |