Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

Working with ADC128D818 12 bit ADC & system monitor

 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM Project Blog
View previous topic :: View next topic  
Author Message
Paulvk

Bascom Member



Joined: 28 Jul 2006
Posts: 1257
Location: SYDNEY

australia.gif
PostPosted: Mon Jul 08, 2013 8:41 am    Post subject: Working with ADC128D818 12 bit ADC & system monitor Reply with quote

Now while working with the MAX1238/9 12 bit ADC and looking for low cost devices this one came up http://www.ti.com/product/adc128d818?qgpn=adc128d818

This is a very interesting device it is a 12bit 8 channel ADC like the max1239 (see other blog) but has other functions as well, it has a temperature sensor on the last channel, it has upper and lower limit registers for each channel which if exceeded cause an interrupt any of these can be masked if not wanted , it will continually monitor its channels comparing this with no work by the micro thus it can be set up to monitor a system with analog output sensors and interrupt the micro if an out off limits value occurs. All this in a low cost device for around $4 AU.
I intend using them in the tree linear power supplies I am rebuilding they will monitor current, voltage and temperature levels sending an interrupt to the AVR if they are exceeded.

Nine devices can be on the buss even though it only has A0 & A1 pins it achieves this by having them as tri-state LOW, HIGH & MID (half of supply voltage).

Not a lot of code yet but this reads the internal setting registers.

Regards Paul.

Code:


 ' send the register location to ADC

  I2cstart                                                  ' Generate start code  write
  I2cwbyte &H3A                                             ' send address write
  I2cwbyte &B0000_0000                                      ' register address in ADC128 see data sheet
  I2cstop                                                   'stop buss

 ' Now start buss again and read the byte/s from register location previously sent
  I2cstart                                                  'start buss
  I2cwbyte &H3B                                             ' Generate start code read
  'I2crbyte Adc128l , ack                                    'for two bytes
  I2crbyte Adc128h , Nack                                   'get value from register
  I2cstop                                                   'stop buss



 Print Bin(adc128h)
'Print Bin(adc128l)

 
Back to top
View user's profile
Paulvk

Bascom Member



Joined: 28 Jul 2006
Posts: 1257
Location: SYDNEY

australia.gif
PostPosted: Mon Jul 08, 2013 9:53 am    Post subject: Reply with quote

Step two write to the registers:

This code first reads the value in the interrupt mask register (0000_0000 default) then writes 1001_1001 to it then reads it again to see the value changed Note the reading of the register is for debug purposes not needed in final code.


Regards Paul.

Code:


'debug code
   I2cstart                                                  ' Generate start code  write
  I2cwbyte &H3A                                             ' send address write
  I2cwbyte &H03                                             ' register address in ADC128 see data sheet
  I2cstop                                                   'stop buss

 ' Now start buss again and read the byte/s from register location previously sent
  I2cstart                                                  'start buss
  I2cwbyte &H3B                                             ' Generate start code read
  I2crbyte Adc128l , Ack                                    'for two bytes
  'I2crbyte Adc128h , Nack                                   'get value from register
  I2cstop                                                   'stop buss



 'Print Bin(adc128h)
 Print "1>>" ; Bin(adc128l)                                 'show default



'----------------------------------------
'the wanted code


  I2cstart                                                  ' Generate start code  write
  I2cwbyte &H3A                                             ' send address write
  'interrupt mask register
  I2cwbyte &H03                                             ' register address in ADC128 see data sheet
  I2cwbyte &B1001_1001                                      'write value to register
  I2cstop                                                   'stop buss

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

'debug code
  I2cstart                                                  ' Generate start code  write
  I2cwbyte &H3A                                             ' send address write
  I2cwbyte &H03                                             ' register address in ADC128 see data sheet
  I2cstop                                                   'stop buss

 ' Now start buss again and read the byte/s from register location previously sent
  I2cstart                                                  'start buss
  I2cwbyte &H3B                                             ' Generate start code read
  I2crbyte Adc128l , Ack                                    'for two bytes
  'I2crbyte Adc128h , Nack                                   'get value from register
  I2cstop                                                   'stop buss



 'Print Bin(adc128h)
 Print "2>>>" ; Bin(adc128l)                                'show new value


 


Terminal screen showing changes
Back to top
View user's profile
Paulvk

Bascom Member



Joined: 28 Jul 2006
Posts: 1257
Location: SYDNEY

australia.gif
PostPosted: Tue Jul 09, 2013 12:20 pm    Post subject: Reply with quote

Now that we can read and write to the chip we can get it working.

Since it can measure temperature we will read this value
Now first we must > 1: Enable startup of monitoring operations
Then >1: Continuous Conversion Mode
We set bit 0 in register H00 to 1 then bit 0 in reg H07 to 1 after this we read the value from reg H27 this will be the temperature value in TWO's Compliment Note that "I2creceive &H3B , Vtemp" the variable Vtemp is an Integer because Bascom stores integers as TWO's Compliment thus Bascom will convert it to a number in normal human form for us!

Now that we have the chip working telling us the temperature it is now only a matter of writing values to the other registers and reading the converted values from the others.

See in the tables below for involved registers and note the order in which you program registers as the chip must be in shutdown mode to program some.

Regards Paul.


Code:


  Local Vtemp As Integer     ' TWO's compliment!

  'WRITE TO THE REGISTERS

  I2cstart                                                  ' Generate start code  write
  I2cwbyte &H3A                                             ' send address write
  'interrupt mask register
  I2cwbyte &H07                                             ' register address in ADC128 see data sheet
  I2cwbyte &B0000_0001                                      'write value to register
  I2cstop                                                   'stop buss


  I2cstart                                                  ' Generate start code  write
  I2cwbyte &H3A                                             ' send address write
  'interrupt mask register
  I2cwbyte &H00                                             ' register address in ADC128 see data sheet
  I2cwbyte &B0000_0001                                      'write value to register
  I2cstop                                                   'stop buss


  'READ THE VALUE FROM REG H27

  I2cstart                                                  ' Generate start code  write
  I2cwbyte &H3A                                             ' send address write
  I2cwbyte &H27                                             ' register address in ADC128 see data sheet
  I2cstop                                                   'stop buss

  I2creceive &H3B , Vtemp


  'I2cstart                                                  'start buss
  'I2cwbyte &H3B                                             ' Generate start code read
  'I2crbyte Tempval1 , Ack                                   'for two bytes
  'I2crbyte Tempval2 , Nack                                  'get value from register
  'I2cstop                                                   'stop buss
   Print "TEMP>>>>" ; Bin(vtemp)
   Print "TEMP>>>>" ; Vtemp



 
Back to top
View user's profile
Display posts from previous:   
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM Project Blog 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