Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

HX711 ADC 24 bits

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    www.mcselec.com Forum Index -> BASCOM-AVR Archive
View previous topic :: View next topic  
Author Message
hapra

Bascom Member



Joined: 20 Sep 2008
Posts: 27

blank.gif
PostPosted: Mon Oct 13, 2014 6:30 pm    Post subject: HX711 ADC 24 bits Reply with quote

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
View user's profile
Evert :-)

Bascom Expert



Joined: 18 Feb 2005
Posts: 2126

netherlands.gif
PostPosted: Mon Oct 13, 2014 8:21 pm    Post subject: Reply with quote

Try
Code:

Addo Alias Pind.5                                          'I use pin D.5 as input Databit
 

_________________
www.evertdekker.com Bascom code vault
Back to top
View user's profile Visit poster's website
Dibor

Bascom Member



Joined: 04 Dec 2004
Posts: 126
Location: ISRAEL

israel.gif
PostPosted: Tue Oct 14, 2014 11:27 am    Post subject: Reply with quote

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
View user's profile MSN Messenger
hapra

Bascom Member



Joined: 20 Sep 2008
Posts: 27

blank.gif
PostPosted: Tue Oct 14, 2014 6:49 pm    Post subject: Reply with quote

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 Rolling Eyes
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
View user's profile
Duval JP

Bascom Member



Joined: 22 Jun 2004
Posts: 978
Location: France

france.gif
PostPosted: Sat Oct 18, 2014 2:27 pm    Post subject: Reply with quote

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 Wink
Back to top
View user's profile Visit poster's website
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5197
Location: Holland

blank.gif
PostPosted: Tue Oct 21, 2014 9:57 pm    Post subject: Reply with quote

Quote:
I look at Bascom AVR Help, there is no Dword

Actually it is mentioned in the language Fundamentals section.

_________________
Mark
Back to top
View user's profile Visit poster's website
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    www.mcselec.com Forum Index -> BASCOM-AVR Archive All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum