right I2C driver for PCF8591
Rob v.d. berg
Posts: 81
Hoi,
I want to convert javelin stuf to spin. For the javelin it was easy to read the analoge inputs·(AIN0 and·AIN1) of the·PCF8591.
*** JAVELIN CODE *******
··· PCF8591.write(0x04); // internal osc on, autoincrement·4-single ended measurements
····· // read
··· PCF8591_Chan_0 = PCF8591.read(); //throw the first away
··· PCF8591_Chan_0 = PCF8591.read(); //reading AIN0
··· PCF8591_Chan_1 = PCF8591.read(); //reading AIN1
I have done the same in spin with the basic I2C PCF8574_driver:
AIN0·> 3,65 volt 3,65/5volt * 255·must give 186
AIN1 > 3,37 volt 3,37/5volt * 255 must give 172
AIN2 > gnd
AIN3 > gnd
++++++++++++++++++++++++++++++++++++++++++++++++++++++++
con
·· ADC_Address = 72 'PCF8591 base·address $48
VAR
· long ADCval_ch0,ADCval_ch1
OBJ
··· IO·: "PCF8574_Driver"
repeat
··· IO.OUT(ADC_Address, %00000100) ' 0x04· / internal osc on, autoincrement 4-single
····················································'ended measurementscontrol byte
··· 'read channel 0
··· ADCval_ch0 := IO.IN(ADC_Address)
··· ADCval_ch0 := IO.IN(ADC_Address)
··· ADCval_ch1 := IO.IN(ADC_Address)
··· waitcnt(40_000_000 + cnt)
But the readings values are very strange.
chan0: 10100000 160 | chan1: 00000000 0
chan0: 00000000 0 | chan1: 11111111 -1
is there anyone who has·one is?,·maybe with a other I2C drive?
Rob.
·
I want to convert javelin stuf to spin. For the javelin it was easy to read the analoge inputs·(AIN0 and·AIN1) of the·PCF8591.
*** JAVELIN CODE *******
··· PCF8591.write(0x04); // internal osc on, autoincrement·4-single ended measurements
····· // read
··· PCF8591_Chan_0 = PCF8591.read(); //throw the first away
··· PCF8591_Chan_0 = PCF8591.read(); //reading AIN0
··· PCF8591_Chan_1 = PCF8591.read(); //reading AIN1
I have done the same in spin with the basic I2C PCF8574_driver:
AIN0·> 3,65 volt 3,65/5volt * 255·must give 186
AIN1 > 3,37 volt 3,37/5volt * 255 must give 172
AIN2 > gnd
AIN3 > gnd
++++++++++++++++++++++++++++++++++++++++++++++++++++++++
con
·· ADC_Address = 72 'PCF8591 base·address $48
VAR
· long ADCval_ch0,ADCval_ch1
OBJ
··· IO·: "PCF8574_Driver"
repeat
··· IO.OUT(ADC_Address, %00000100) ' 0x04· / internal osc on, autoincrement 4-single
····················································'ended measurementscontrol byte
··· 'read channel 0
··· ADCval_ch0 := IO.IN(ADC_Address)
··· ADCval_ch0 := IO.IN(ADC_Address)
··· ADCval_ch1 := IO.IN(ADC_Address)
··· waitcnt(40_000_000 + cnt)
But the readings values are very strange.
chan0: 10100000 160 | chan1: 00000000 0
chan0: 00000000 0 | chan1: 11111111 -1
is there anyone who has·one is?,·maybe with a other I2C drive?
Rob.
·
Comments
I know but it was working by the Javelin direct. I will start to make it with·the·basic_I2C_driver object as basis.
thanks for your reply
Rob.
Thanks, that push me in the right direction, as PUB i must think as:
·'get only channel 0,1,2 or 3
__________________________________
PUB GetSingleADC(SCL,Channel)
· DoControl(SCl, 0, 0, 0, Channel, 0)
· return GetAnalog(SCL)
___________________________________
*Peter*
Mike, great its works thanks a lot.
Rob
Brief background - the PCF8591 is a chip that works on the I2C bus and gives you 1 analog output and 4 analog inputs. 8 bit resolution.
I had a urgent need for a pump controller and I needed a display and some analog inputs and outputs. This thread has come to the rescue!
After much work with many microcontrollers, in terms of a simple text display and it terms of dollars per character, nothing beats the Propeller driving a car reversing display. Essentially this is a little TV display and for those familiar with the propeller, driving such a display is three resistors and a RCA socket and ready made code in the Obex. Less wires and cheaper and more characters than, say, 20x4 LCD displays.
And I want to read a pressure gauge to measure the height in a tank. The MPX5050 is perfect for this as it has an inbuilt amplifier so all the voltages are just right for the propeller.
The standard analog input using two pins and a 100k and 150k and two 1nf caps stumped me though. I think it is probably because the components have to be surface mount and right up next to the chip. I can't do that on my setup and my components were 10cm awy and in any case, an evening of debugging got nowhere. So the PCF8591 came to the rescue.
Well, it works brilliantly. Uses the I2C bus so it doesn't use any propeller pins as such as the I2C shares the EEPROM.
Datasheet is here http://www.nxp.com/documents/data_sheet/PCF8591.pdf
I modified Mike's code a little by adding some more comments.
Mike, James Burrows added a package to the Obex based on your code http://obex.parallax.com/object/27
I wonder if there is a way of adding the PCF8591 to the package? I don't want to duplicate what is already done, but what would be ideal is a search for PCF8591 comes up with a little working demo package.