Simple way to compare 1 input against multiple voltage thresholds?

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
JoBr_1593366
Level 5
Level 5
100 sign-ins 50 questions asked 100 replies posted

I know I can do it in software with an ADC, etc. but is there a way to do it that produces hardware outputs?

For example, I tried using the Scanning Comparator, with the input voltage connected to all terminals, using "Internal VDAC" with "per channel" voltage thresholds.  Theoretically it would then continually scan the input vs the 3 thresholds and output 3 hardware logic signals, one for each case, updating them automatically in hardware.

pastedImage_1.png

But it doesn't seem to be able to route this because of the input MUX.  It gives a confusing error message:

Cannot use pin PIN(0) as digital HW output when it is connected to an analog HW mux.

If a GPIO pin is connected to an AMuxHW component, its digital input is expected to be used by the matching digital control signal on the AMuxHW component. So this GPIO pin's digital input signal should be reserved for the matching digital control signal on AMuxHW component only.

Actually the pin is not set to anything other than analog input, but I think it's just because it can't connect a single GPIO to multiple MUX inputs.

Any other solutions?  The thresholds in this case are 600, 1380, and 1490 mV, so not something I can just generate with VRef components and use separate comparators.  Any way to make the Mux accept the single pin input?

0 Likes
1 Solution

JoBr,

With Scanning Comparator all 3 pins must be connected  externally.

The easiest way would be to use an ADC to read input voltage and make a decision. If you have enough resources left, use 3 comparators and 3 DACS to set Vref.

/odissey1

View solution in original post

14 Replies
EvPa_264126
Level 7
Level 7
500 replies posted 250 replies posted 100 likes received

like so...adc1.png

odissey1
Level 9
Level 9
First comment on KBA 1000 replies posted 750 replies posted

JoBr,

The Scanning Comparator mux approach should work, but each input must be connected to the individual pin.

What scan rate is acceptable for your application?

/odissey1

0 Likes

BoTa_264741 wrote:

each input must be connected to the individual pin.

There's only one input.

What scan rate is acceptable for your application?

It's not very important.  1 kHz should be plenty.

Actually...  Probably the scan rate doesn't matter too much, but it would matter that all outputs get changed at the same time.

0 Likes

JoBr,

With Scanning Comparator all 3 pins must be connected  externally.

The easiest way would be to use an ADC to read input voltage and make a decision. If you have enough resources left, use 3 comparators and 3 DACS to set Vref.

/odissey1

JoBr,

Only one input that can be wired to three other PSoC pins.

About the error the component throws:  I cannot see any reason why the component couldn't allow for internal analog routing.   Does anyone monitoring this discussion know of a reason for this restriction?

There is another solution, someone could re-write the component validation logic to allow for internal analog connections.

Len

Len
"Engineering is an Art. The Art of Compromise."

JoBr,

Here's a schematic snip of the circuit /odissey1 is recommending.

pastedImage_0.png

Len

Len
"Engineering is an Art. The Art of Compromise."
Len_CONSULTRON
Level 9
Level 9
Beta tester 500 solutions authored 1000 replies posted

JoBr,

The error you are getting is because the ScanComp component requires that all Analog inputs into the AMux be assigned to only one pin each.  This is a component requirement.  I don't know why the requirement is there, but that's how they wrote the component validation.

Len

Len
"Engineering is an Art. The Art of Compromise."
RodolfoGL
Employee
Employee
250 solutions authored 250 sign-ins 5 comments on KBA

We have a component that does just that.

http://www.cypress.com/file/132911

Rodolfo,

Will the Voltage Fault Detector component allow for internally routed analog connections to anything other than directly to IO?

Len

Len
"Engineering is an Art. The Art of Compromise."
0 Likes

I'm not sure. Internally it uses the AnalogHwMux. So it depends if there is a possible route for that. In the worst case, you could burn a pin and connect the two pins externally. One pin goes to the Voltage Fault Detector, the other one to the desire analog component.

0 Likes

RodolfoG_11 wrote:

We have a component that does just that.

http://www.cypress.com/file/132911

This seems promising.  It essentially works as a comparator on multiple inputs, with possibly multiple thresholds for a single input, right?

pastedImage_1.png

I still need to learn about the clock source, settings, etc. but it seems like it could work, and it fits in my project's hardware limitations.  (I only have one VDAC left.)

0 Likes

JoBr,

I believe that using FaultDetector faces the same problem, that due to using hardware AMux each input must be connected to an individual pin. Another thing is that FaultDetector parses inputs sequentially, so there is some latency. I believe that it also uses DMA to update VDAC setting, so increasing the speed also eats away DMA resources. You also have to handle correctly the sequence of events when Vinp > V1, V2 and V3.

/odissey1

Well I have multiple inputs connected to one pin as in my screenshot and it builds, unlike the scanning comparator, so I think that's ok.  I'm not sure about sequence of events, I'll have to think about that.

0 Likes
lock attach
Attachments are accessible only for community members.
odissey1
Level 9
Level 9
First comment on KBA 1000 replies posted 750 replies posted

JoBr,

Attached is a project using ADC_SAR to continuously sample a single input and indicate status on the output pins 2, 3 and 4.

Project uses custom version of the ADC_SAR modified with hardware bus output. The output value continuously compared against 3 predefined constant values (which should correspond to requested threshold limits). A registered lookup table selects the highest output. All operations are performed in hardware and  processor is not involved. As shown, adc scanning rate is 100kHz, but it can be increased to 1MHz if necessary.

Attached are demo project and custom component library, which should be installed using Project->Dependencies->Add..

The project is untested.

/odissey1

SAR_ADC_comparator_01a_A.png