View previous topic :: View next topic |
Author |
Message |
hapra
Joined: 20 Sep 2008 Posts: 27
|
Posted: Mon Oct 13, 2014 6:30 pm Post subject: HX711 ADC 24 bits |
|
|
Hi all,
I hope my question is really new about Chip HX711 ADC 24 bits, in this forum.
I am using ATmega32 MCU with crystal 4Mhz to communicate with HX711 Dual-Channel Weighing Sensor Module, this module image can be found on the internet.
While the HX711 datasheet in http://www.dfrobot.com/image/data/SEN0160/hx711_english.pdf
I am trying to convert from C (page 8th) to Bascom code, but it does not work at all even timing clock is set with different timing.
It means the return value is always 0 (zero).
Can anyone help me, may have a code that has been successfully working?
Thank you in advance.
Original code:
Code: |
//********************************************************
//*** C Coding ********************************************
//********************************************************
sbit ADDO = P1^5;
sbit ADSK = P0^0;
unsigned long ReadCount(void){
unsigned long Count;
unsigned char i;
ADDO=1;
ADSK=0;
Count=0;
while(ADDO);
for (i=0;i<24;i++){
ADSK=1;
Count=Count<<1;
ADSK=0;
if(ADDO) Count++;
}
ADSK=1;
Count=Count^0x800000;
ADSK=0;
return(Count);
}
|
My snippet code conversion:
Code: |
'********************************************************
'*** Bascom *********************************************
'********************************************************
Adsk Alias Portd.4 'I use pin D.4 as output Clock
Addo Alias Portd.5 'I use pin D.5 as input Databit
Config Adsk = Output
Config Addo = Input
Dim Count As Long
'-------------------------------------------------------------------------------
Function HX711_Read() As Long
'-------------------------------------------------------------------------------
Local I As Byte
'ADDO = 1 'I also give quotation marks at this alternately coz as input, not output
Adsk = 0 'clock LOW
Count = 0 'reset variable
While Addo = 1 'wait until data ready
Wend
'Shiftin ADDO , ADSK , Count , 1 , 24 , 10 --> similar ?
For I = 1 To 24 'channel A, gain 128x
Adsk = 1 'clock HIGH
Shift Count , Left , 1 'shift to left 1 bit
Adsk = 0 'clock LOW
If Addo = 1 Then Incr Count 'give bit 1 for LSB, otherwise 0
Next
Adsk = 1 'clock HIGH
Count = Count Xor &H800000 '0x800000
Adsk = 0 'clock LOW
Hx711_read = Count 'returned value
End Function
|
(BASCOM-AVR version : 2.0.7.3 , Latest : 2.0.7.7 ) |
|
Back to top |
|
|
Evert :-)
Joined: 18 Feb 2005 Posts: 2156
|
|
Back to top |
|
|
Dibor
Joined: 04 Dec 2004 Posts: 137 Location: ISRAEL
|
Posted: Tue Oct 14, 2014 11:27 am Post subject: |
|
|
Also instead Long use Dword because in C code used unsigned Long(Bascom doesn't has unsigned) so Dword is 32 bit unsigned variable as unsigned Long in C
But if you get value less then 32bit (24 bit for example)you do not need make any changes
Regards. |
|
Back to top |
|
|
hapra
Joined: 20 Sep 2008 Posts: 27
|
Posted: Tue Oct 14, 2014 6:49 pm Post subject: |
|
|
Hi Evert,
Yes, your suggestion correctly, I had to type Pind.5 not Portd.5
Why I always forget about Portx.y for output bit assignment and Pinx.y for input bit assignment
Thank you very much for the correction.
Hi Dibor,
I look at Bascom AVR Help, there is no Dword, but when I try to compile the result is successful, I just realize that Dword actually already supported.
And currently I am still using 24-bits only for this purpose.
Thank you for the very useful information. |
|
Back to top |
|
|
Duval JP
Joined: 22 Jun 2004 Posts: 1161 Location: France
|
Posted: Sat Oct 18, 2014 2:27 pm Post subject: |
|
|
good work !
when you finish it, it would be nice to share your work with other bascom's users in "Share your working BASCOM-AVR code here"
many thanks
JP |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5921 Location: Holland
|
Posted: Tue Oct 21, 2014 9:57 pm Post subject: |
|
|
Quote: | I look at Bascom AVR Help, there is no Dword |
Actually it is mentioned in the language Fundamentals section. _________________ Mark |
|
Back to top |
|
|
|