News:

Let's find out together what makes a PIC Tick!

Main Menu

AD7705 driver

Started by Yves, Jun 06, 2025, 04:09 PM

Previous topic - Next topic

Yves

Hi all,

Is anyone has wrote a driver for the AD7705?

cheers,

Yves
Yves

Pepe

#1
I can't simulate it but try this

Pepe

ANOTHER UNTESTED EXAMPLE

;-------------------------------------------------------------------------------
;**** Added by Fuse Configurator ****
; Use the Fuse Configurator plug-in to change these settings

Device = 16F877A

Config FOSC_HS, WDTE_OFF, PWRTE_OFF, BOREN_OFF, LVP_OFF, CPD_OFF, WRT_OFF, DEBUG_OFF, CP_OFF

;**** End of Fuse Configurator Settings ****
;-------------------------------------------------------------------------------

 
Declare Xtal = 20

Declare Optimiser_Level = 3
Declare Bootloader off
Declare Create_Coff On
Declare Reminders off       
Declare Watchdog off

Declare LCD_Interface 4
Declare LCD_DTPin PORTD.0 ' Used for 4-line interface
Declare LCD_ENPin PORTD.4
Declare LCD_RSPin PORTD.5
Declare LCD_Lines 2
Declare LCD_Type  0

'AD7705
Symbol CLK=PORTC.4 'Clock pin
Symbol SO=PORTC.6 ' AD7705 Data out pin.
Symbol SI=PORTC.5 ' AD7705 Data in pin

Output PORTC.4
Output PORTC.6
Input PORTC.5
Input PORTC.3

'AD7705
Dim Send As Byte 'byte sent to communication register of AD7705
Dim rec As Byte 'byte received from AD7705:only for communication register, set-up register and clock register (8 bit registers)
Dim ready As Byte 'AD7705 Ready BIT
Dim ad As Word 'ad converter value read from AD7705
Dim ad2 As Word 'ad converter value read from AD7705

Clear 'clear all variables

DelayMS 1000
Print At 1,1, "Test" ' line 1
DelayMS 2000

'MX7705
MX7705Ini()

Dim countd As Word  = 0

Do
'Calib 'self-calibration
Send = $10 ' WRITE TO THE COMMUNICATIONS REGISTER. SELECT CHANNEL 0 AND SET NEXT OPERATION AS A WRITE TO THE SETUP REGISTER.(0x10).
SHOut SI, CLK, 5, [Send\8] ' Send command to communication register
rec = $44 ' WRITE TO THE SETUP REGISTER. SET SELF-CALIBRATION MODE, GAIN TO 0, UNIPOLAR MODE, UNBUFFERED MODE.
' BEGIN SELF-CALIBRATION/CONVERSION BY CLEARING FSYNC.(0x44)
SHOut SI, CLK, 5, [rec\8] ' Send value to the selecte register
While PORTC.3 = 1:Wend 'wait for valid data to be received. Er angivet under self calibration mode.
' Note that after the self calibration, AD7705 start free conversion cycle.
'AD7705
While PORTC.3 = 1 'wait for valid data to be received
Inc countd
Print At 1,1, "Count:", Dec countd ' line 1
Wend 'wait for valid data to be received
Send = $38 ' Read the 16 bit DATA Register, channel 0.
SHOut SI, CLK, 5, [Send\8] ' Send read command and data register address
SHIn SO, CLK, 6, [ad\16] ' Read 16 bit data
Print At 2,1,"V:", Dec ad ,"  "' Line 2

'delayms 1000
'Calib 'self-calibration
Send=$11 ' WRITE TO THE COMMUNICATIONS REGISTER. SELECT CHANNEL 1 AND SET NEXT OPERATION AS A WRITE TO THE SETUP REGISTER.(0x10).
SHOut SI, CLK, 5, [Send\8] ' Send command to communication register
rec = $44 ' WRITE TO THE SETUP REGISTER. SET SELF-CALIBRATION MODE, GAIN TO 0, UNIPOLAR MODE, UNBUFFERED MODE.
' BEGIN SELF-CALIBRATION/CONVERSION BY CLEARING FSYNC.(0x44)
SHOut SI, CLK, 5, [rec\8] ' Send value to the selecte register
While PORTC.3 = 1:Wend 'wait for valid data to be received. Er angivet under self calibration mode.
' Note that after the self calibration, AD7705 start free conversion cycle.
While PORTC.3 = 1 'wait for valid data to be received
Inc countd
Print At 1,1, "Count:", Dec countd ' line 1
Wend 'wait for valid data to be received
Send = $39 ' Read the 16 bit DATA Register, channel 1.
SHOut SI, CLK, 5, [Send\8] ' Send read command and data register address
SHIn SO, CLK, 6, [ad\16] ' Read 16 bit data
Print At 2,1,"Amp:",Dec ad ,"   "' Line 2

If countd > 60000 Then countd = 0
Loop
 
Proc MX7705Ini()
'Reset MX7705
Send = $ff
rec = $ff
SHOut SI, CLK, 5, [Send\8] ' Send command to communication register
SHOut SI, CLK, 5, [rec\8] ' Send value to the selecte register
SHOut SI, CLK, 5, [Send\8] ' Send command to communication register
SHOut SI, CLK, 5, [rec\8] ' Send value to the selecte register

'AD7705 set-up Start.
Send = $20 ' WRITE TO THE COMMUNICATIONS REGISTER. SELECT CHANNEL 0 AND SET NEXT OPERATION AS A WRITE TO THE
' CLOCK REGISTER.(0x20)
' Send=$21 ' WRITE TO THE COMMUNICATIONS REGISTER. SELECT CHANNEL 1 AND SET NEXT OPERATION AS A WRITE TO THE
' CLOCK REGISTER.(0x21)
SHOut SI, CLK, 5, [Send\8] ' Send command to communication register
' rec=$0C ' write on clock register: clock division=1, clock bit=1, master clock enabled (bit set to 0),
' bit output rate set to 50hz.
rec = $0f ' write on clock register: clock division=1, clock bit=1, master clock enabled (bit set to 0),
' bit output rate set to 500hz
SHOut SI, CLK, 5, [rec\8] ' Send value to the selecte register

EndProc


Pepe

#3
fixed program