Oh no, not the PCF8591 again...

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
Hairyloon
Normal user
Posts: 42
Joined: 19 Dec 2018, 00:30

Oh no, not the PCF8591 again...

#1 Post by Hairyloon » 13 Jul 2019, 00:29

How can I use a PCF8591 as a comparator with ESP Easy?
I understand that I would need to set the control byte to the appropriate value, but I don't know how to do that.
Last edited by Hairyloon on 17 Jul 2019, 17:44, edited 1 time in total.

User avatar
ThomasB
Normal user
Posts: 406
Joined: 17 Jun 2018, 20:41
Location: USA

Re: PCF8591 as comparator.

#2 Post by ThomasB » 13 Jul 2019, 05:30

The plugin only provides simple analog reads of the four inputs. No other functions are supported.

-Thomas

Hairyloon
Normal user
Posts: 42
Joined: 19 Dec 2018, 00:30

Re: PCF8591 as comparator.

#3 Post by Hairyloon » 13 Jul 2019, 10:26

ThomasB wrote:
13 Jul 2019, 05:30
The plugin only provides simple analog reads of the four inputs. No other functions are supported.
That may be true, but in order to read the simple analogue input, the plugin must send a control byte to the chip: I just need to send a different control byte.
I may have to hack the plugin to do that, and being new to this game, I'm not sure how big a deal that will be.

User avatar
ThomasB
Normal user
Posts: 406
Joined: 17 Jun 2018, 20:41
Location: USA

Re: PCF8591 as comparator.

#4 Post by ThomasB » 13 Jul 2019, 18:24

I'm not sure how big a deal that will be.
Getting familiar with the PlatformIO IDE will probably be the hardest part.

You mentioned that you want to use the PCF8591 as a comparator. This can be done in ESPEasy's rules. Read the ADC channel, then have a rule compare it to the "reference" voltage (another ADC channel, system variable, or hard coded value).

- Thomas

Hairyloon
Normal user
Posts: 42
Joined: 19 Dec 2018, 00:30

Re: PCF8591 as comparator.

#5 Post by Hairyloon » 14 Jul 2019, 01:59

ThomasB wrote:
13 Jul 2019, 18:24
I'm not sure how big a deal that will be.
Getting familiar with the PlatformIO IDE will probably be the hardest part.
Yeah, I tried that once and gave up on it. I may look for another way...
You mentioned that you want to use the PCF8591 as a comparator. This can be done in ESPEasy's rules. Read the ADC channel, then have a rule compare it to the "reference" voltage (another ADC channel, system variable, or hard coded value)
I can see how that would sort of work, but I want to measure a small voltage between two points, and comparing the two voltages in software would not have the resolution.
Much better to set it up as a comparator:
2019-07-13.png
2019-07-13.png (245.54 KiB) Viewed 4278 times

User avatar
ThomasB
Normal user
Posts: 406
Joined: 17 Jun 2018, 20:41
Location: USA

Re: PCF8591 as comparator.

#6 Post by ThomasB » 14 Jul 2019, 03:22

The PCF8591 does not provide user access to its internal comparator (it's assigned to the successive approximation logic). But using the differential input feature with a low reference voltage is a trick worth playing with if the rule based concept does not work. Keep in mind that this is not the same as comparator solution, just differentially driven ADC operation.

If microvolt threshold accuracy is needed then a dedicated comparator chip might be the easiest solution. Especially since you don't have to make a custom plugin. Plenty of chips to choose from, so nothing to worry about. DIP package, five wires, done. Sometimes solder is the best software.

- Thomas

Hairyloon
Normal user
Posts: 42
Joined: 19 Dec 2018, 00:30

Re: PCF8591 as comparator.

#7 Post by Hairyloon » 14 Jul 2019, 15:28

ThomasB wrote:
14 Jul 2019, 03:22
Keep in mind that this is not the same as comparator solution, just differentially driven ADC operation.
Ah, am I using the wrong terminology? OK, so what's the difference?
And how do I get ESPEasy to use the differential input?
If microvolt threshold accuracy is needed then a dedicated comparator chip might be the easiest solution.
The easiest solution (at least on one level) is to use what I've got available... I've got an ADS1115 in the box, if that would be any better?

User avatar
ThomasB
Normal user
Posts: 406
Joined: 17 Jun 2018, 20:41
Location: USA

Re: PCF8591 as comparator.

#8 Post by ThomasB » 14 Jul 2019, 18:50

Ah, am I using the wrong terminology? OK, so what's the difference?
A comparator changes logic state when the threshold voltage is exceeded.
A differential ADC's two inputs are subtracted from the other. This is intended to reduce common mode noise on input signals.
I've got an ADS1115 in the box, if that would be any better?
It has greatly increased ADC resolution. I would encourage you to try that chip (using single ended mode) with the rule based comparison method mentioned earlier.

- Thomas

Hairyloon
Normal user
Posts: 42
Joined: 19 Dec 2018, 00:30

Re: PCF8591 as comparator.

#9 Post by Hairyloon » 14 Jul 2019, 20:02

ThomasB wrote:
14 Jul 2019, 18:50
I would encourage you to try that chip (using single ended mode) with the rule based comparison method mentioned earlier.
Why single ended?
I'm not seeing the sense to that when the differential measurement seems to be exactly the tool for the job. Perhaps I've not understood what you mean...

User avatar
ThomasB
Normal user
Posts: 406
Joined: 17 Jun 2018, 20:41
Location: USA

Re: PCF8591 as comparator.

#10 Post by ThomasB » 14 Jul 2019, 23:24

Why single ended?
Because I have high confidence single ended ADC operation will work without much fuss. I'm not convinced the differential input will work as you intended (it's there for applications that need noise immunity, not analog compare). But give it a try since experimentation is fun. And it would be an interesting trick to do.
I'm not seeing the sense to that when the differential measurement seems to be exactly the tool for the job.
I'll flip that comment back to you; I'm not seeing the sense in using an ADC when the info about your project points to using a common comparator chip. For example, I would grab an LM393 (or any other single supply comparator) and configure ESPEasy with the Switch Input plugin to read the state.

But this is your project. And there are many solutions to choose from. So just do it the way that excites you the most.

- Thomas

Hairyloon
Normal user
Posts: 42
Joined: 19 Dec 2018, 00:30

Re: PCF8591 as comparator.

#11 Post by Hairyloon » 15 Jul 2019, 00:52

ThomasB wrote:
14 Jul 2019, 23:24
I'm not seeing the sense in using an ADC when the info about your project points to using a common comparator chip. For example, I would grab an LM393 (or any other single supply comparator) and configure ESPEasy with the Switch Input plugin to read the state.
But I want to read the value, not the state...

User avatar
ThomasB
Normal user
Posts: 406
Joined: 17 Jun 2018, 20:41
Location: USA

Re: PCF8591 as comparator.

#12 Post by ThomasB » 15 Jul 2019, 02:50

But I want to read the value, not the state...
OK, a comparator won't work. Wire up a ADC and put it to work.

- Thomas

Hairyloon
Normal user
Posts: 42
Joined: 19 Dec 2018, 00:30

Re: PCF8591 as comparator.

#13 Post by Hairyloon » 15 Jul 2019, 10:48

ThomasB wrote:
15 Jul 2019, 02:50
But I want to read the value, not the state...
OK, a comparator won't work. Wire up a ADC and put it to work.
Which brings us back to the original question of how to tell the chip to measure the comparative voltage...
Is there the means to send a specific command to a given I2C device?

User avatar
ThomasB
Normal user
Posts: 406
Joined: 17 Jun 2018, 20:41
Location: USA

Re: PCF8591 as comparator.

#14 Post by ThomasB » 15 Jul 2019, 17:09

If you mean you want to enable ADS1115's differential mode, then configure its plugin for Differential operation. It's in the "Input Multiplexer" drop down list. Reading ADC values will use differential operation after you do that.

If the ADC's differential mode trickery does not work as you expected, then use Single-Ended operation and rules, as mentioned earlier.

Not much more to say. Your turn to just try it out and experiment.

- Thomas

Hairyloon
Normal user
Posts: 42
Joined: 19 Dec 2018, 00:30

Re: PCF8591 as comparator.

#15 Post by Hairyloon » 15 Jul 2019, 19:17

Ah yes.
I've not found the box with the module yet, so not looked at the interface for it. Sorry, I'll let you know in due course. It may be a while: it's dropped off my priority list.
Thank you for the help.

Hairyloon
Normal user
Posts: 42
Joined: 19 Dec 2018, 00:30

Re: Oh no, not the PCF8591 again...

#16 Post by Hairyloon » 19 Jul 2019, 00:58

I hope this isn't a breach of forum etiquette, but since I'm still on with the PCF8591, I thought it better to change the title and carry on here rather than start a new thread, even though it is a completely different issue.
I've got a PCF8591 set up measuring some voltages from sensors, which I would expect to vary over time, but generally quite slowly, whereas these ones are bouncing up and down like nobody's business: one bouncing erratically from 130 to 230, another from 0 to 80.
My first thought is that I've wired it up wrong, but I cannot see how so. Interference is a possibility, but there is nothing else on the circuit or plugged in near to it, so I think not.

me4blogs
Normal user
Posts: 1
Joined: 03 Aug 2019, 17:30

Re: Oh no, not the PCF8591 again...

#17 Post by me4blogs » 03 Aug 2019, 18:12

I am having similar issue - all works ok when only one input is defined in devices, but more give odd results. I was having similar issue when testing PCF8591 with RPi, solution was to introduce slight delay (5ms) between setting which input we want, and reading its value. Might be why we are seeing seemingly random values.

Post Reply

Who is online

Users browsing this forum: No registered users and 23 guests