PCF8591 Library

I’m trying to code a library for the PCF8591 (a 4 channel 8-bit ADC over I2C). I’ve got the basic code working. Readings work well when sampled once every ~700ms. When I drop the sampling to ~500ms get erroneous readings. Values will range from low (0) to high (255) and somewhere in between and just bounce around. I was wondering if anyone would have suggestion on the code or what might be causing these erroneous readings.


PCF8591.h (899 Bytes)

PCF8591.cpp (1.46 KB)

There's this old thread: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1276092007

A very good thread it is (until it's hijacked...) Unfortunately, I have already tried the assorted items mentioned in it.

You really should provide a link to the spec sheet if you really want help...

Are these the correct times?

tADC conversion time - - 90 ms
fADC sampling/conversion rate - - 11.1 kHz

if so -- yes it is your program.

The chip does not have an interrupt out line which would sort out some issues...

What are your specs for correct performance? You don't say... how much time between readings?

Consider using a DS1307 with the oscillator running and using the rising edge as an interrupt trigger. If it is too many readings average them....

No code, no specs... hard to help.

Woah WillR! Lighten up on the caffeine!

Yes, those are the times. I didn’t include a link as links break and Google is friendly. I also didinclude code as attachment, not inline.

Now kindly please elaborate on why those timing would be “my program” and not suggest a useless RTC when I’m looking for ADC.

Leave off the wise rear-orifice remarks.

Apologies -- did not notice the links. Most people clip code inline. Generally I don't have the time to download and look... I am working on my own projects and have to be at a conference next week -- so time is now limited...

I think everything is in my post.

There is no interrupt "data ready line" on the adc -- so you make one by using the clock oscillator... A data ready line allows you to make an ISR routine so you don't have to worry about timing issues...

Sometimes "other things" interfere with reading sensors --so rather than wait or count delays or clock pulse -- you take the square wave off the clock.

First Library I fixed up was the DS1307 and then the time library -- just for this reason.

See this thread...

I am not a hobbyist so I usually don't have time for long lead ins so I try to get to the point.

Now -- as to the specs... I mean YOUR specs... as well as the data sheer.

What do YOU want from the device -- how fast to read etc... one a day once a year or once a second? 100SPS?

Also -- I do know how to use google -- but if you make it fast to look and it's easy to help you get more.

Finally -- I don't see that I made any rude remarks. (A mistake yes.) If I did not wish to help there would have been no response at all.

Here is a possibility...

The second byte sent to a PCA9691 is stored in its control register and is required to control the PCA9691 function.
The upper nibble of the control register is used for enabling the analog output, and for programming the analog inputs as single-ended or differential inputs. The lower nibble selects one of the analog input channels defined by the upper nibble (see Figure 6).

If the auto-increment flag is set, the channel number is incremented automatically after each A/D conversion.
If the auto-increment mode is selected and the internal oscillator is used, the analog output enable flag in the control byte (bit 6) must be set. This allows the internal oscillator to run continuously, thereby preventing conversion errors resulting from oscillator start-up delay. The analog output enable flag can be reset at other times to reduce quiescent power consumption.

Hit the wrong link first time ... same issue same chip series...


Posting the data Sheet link saves time.

When I hunt for chips, often i get 100 messages offering me a paid service or a free service to find the sheet. It takes time.... and that is exactly what happened this second time as well..

Just make it easy to help. That's all people ask...

Final Note:

You have a delay(100) (Commented out) in your code....

The spec sheets says something like 70us is the conversion time... so you are off by a 1000 times on the requirement... use the microsecond delay function...

And yes -- some chips require that inserted delay --- like the BMP085 -- so I found -- the issue was reversed -- need ms delay -- not us delays..

Cheers and have fun.