ADUC 812

Top  Previous  Next

The 812 has 2 DACS named DAC0 and DAC1.

 

You can use the CONFIG ADUC812 statement to set the DAC behaviour.

The DAC can be powered on or off.

DAC0.POWEROFF will power off the DAC0

DAC1.POWERON will power on the DAC1

 

To force the output of the DAC to 0 volt use :

DAC0.CLEAR

 

To let it output the voltage use :

DAC0.NORMAL

 

The DAC values can be written with the following statements:

DAC0.value = 1024 'or a variable

DAC1.value = word

 

The sync bit is reset and to sync the DAC with the supplied values use :

 

DAC.SYNC

Note that the SYNC method operates on both DACS and so there is no 0 or 1 specified!

 

All the previous methods shown can work with 0 for DAC0 or 1 for DAC1.

 

See the aduc812.bas example:

 

'---------------------------------------------------------------------

'                  ADCU812.bas (c) 2000 MCS Electronics

'       Note that the support for this chip is untested

'       Any feedback appreciated!

'---------------------------------------------------------------------

'Use this dat file

$regfile = "812.dat"

 

'configure ADC

Config Aduc812 = Adcon , Mode = Normal , Clock = 1 , Aquisition = 1 , Timer2 = Disabled , Extrig = Disabled

 

'configure DACS

Config Aduc812 = Dac , Mode = 12 , Range1 = Vref , Range0 = Vref , Clear0 = False , Sync = Enabled , Power0 = On , Power1 = Off

 

Declare Sub Write_ebyte

Declare Sub Read_ebyte

 

'dim variables

Dim Wdac As Word

Dim Adc As Word

 

Dim Eeadr As Word , Eebyte As Byte , Page As Word

'get value from adc channel 0

'note that simulator will halt until you make the adccon2 bit 4 zero.

Adc = Getad(0)

 

'enable dac0 by powering it on

Dac0.poweron

 

'0V to output of dac0

Dac0.clear

 

'put voltage into dacs

Dac0.value = 12

Dac1.value = 500

 

'dac0 was 0V but must work normal now

Dac0.normal

 

'and after setting the value(s) the dacs must be updated with the sync method

Dac.sync

 

'the EEPROM is accessed via pages

'each page is 4 bytes

'to write 1 byte you need to write the whole 4 byte page

'assign eeadr with the address

'and eebyte with the value to write

Eeadr = 100 : Eebyte = 5 : Call Write_ebyte

 

Eeadr = 100 : Call Read_ebyte

Print Eebyte

End

 

Sub Write_ebyte

  Page = Eeadr \ 4                                          'page

  mov edarl,{page}                                          ; page address

  mov econ,#1                                               ; read 4 current bytes

  mov econ,#5                                               ; erase page

  Waitms 20                                                 'wait 20 msecs

  Page = Page * 4

  Page = Eeadr - Page

  If Page = 0 Then

     mov edata1,{eebyte}                                    ; data register to write

  Elseif Page = 1 Then

     mov edata2,{eebyte}                                    ; data register to write

  Elseif Page = 2 Then

     mov edata3,{ebyte}                                    ; data register to write

  Else                                                      'must be 3

     mov edata4,{eebyte}                                    ; data register to write

  End If

  mov econ,#2                                               ; write registers

End Sub

 

Sub Read_ebyte

  Page = Eeadr \ 4                                          'page

  mov edarl,{page}                                          ; page address

  mov econ,#1                                               ; read 4 current bytes

  Page = Page * 4

  Page = Eeadr - Page

  If Page = 0 Then

     mov {EEbyte},edata1                                                 ; data register to read

  Elseif Page = 1 Then

     mov {eebyte},edata2                                                 ; data register to read

  Elseif Page = 2 Then

     mov {eebyte},edata3                                    ; data register to read

  Else                                                      'must be 3

     mov {eebyte},edata4                                    ; data register to read

  End If

  mov econ,#2                                               ; write registers

End Sub

 

End