; Date: 18/06/2008 ; Here are some code fragments that will drive the devices on the 5624 Analogue I/O port. ; They assume default I2C Bus addresses. ;Set up the ADCs. Call this before trying to read the ADCs. TO init ;Make one object that can read any of the 8 12-bit channels: MAKE adc12 Analogue(0,1,64,0) ; (Type, I2C Bus, Address, Channel) ;Set up the 18-bit ADC at 16-bit; no driver object is available. setup_adc16 END ;Set one or both of the DAC outputs. ; Chan is 1 or 2, or 3 for both. ; Val is 0-4095. TO set_dac(chan,val) net.On net.Put(24);Chip address net.Put(chan) ;DAC channel(s) to address. net.Put(%00100000 + val DIV 256 ) ; control bits + Value MSbits net.Put(val) ;Value LSB - no need to mask high bits. net.Off END ;Read a value from the 12-bit ADC ;Chan is 0-7. ;Note: don't really need to define a procedure to do this. ;Init must be called first to MAKE the ADC object. TO read_adc12(chan) return adc12.Value(chan) END ;Initialise the MCP3421 for 16-bit operation and 1:1 input PGA gain. TO setup_adc16 net.Lock net.On net.Put(208) ;Device address net.Put(%00011000);Continuous, 16-bit, 1:1 gain. net.Off net.UnLock END ;Read raw ADC value from the MCP3421. ;init must be called first to initialise the ADC. TO read_adc16 net.Lock net.On net.Put(208+1) ;Device read address. a := net.Get() b := net.GetLast() net.Off net.UnLock RETURN a*256 + b END