Control analog path from code.

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

cross mob
vojec_2946236
Level 1
Level 1

Dear Cypress community,

is it possible to control an analog path in PSoC Creator 4.2 SP0 through some digital object?

pastedImage_0.png

Currently I am dimming an LED by turning LED_OPAMP object on/off by LED_OPAMP_Start(); and LED_OPAMP_Stop(); (It's some kind of PWM)

Is there a way to disable the analog output as if the opamp would be disabled by LED_OPAMP_Stop();

Thank you.

0 Likes
6 Replies
odissey1
Level 9
Level 9
First comment on KBA 1000 replies posted 750 replies posted

vojtech.jeso,

it is unusual to run an LED from Opamp. Typically digital PWM output is used for that purpose. Is there any special need for using Opamp here? From schematic it looks like a Comparator (with digital output) is more appropriate here, and digital output pin can be enabled/disabled using hardware line or simply use the AND gate.

0 Likes

Hi, thank you for your reply, but it should be like it is, because we removed hw opamp and put it into psoc and its output is controling a transistor which controls power to LEDs.

So the output needs to be analog.

0 Likes

vojtech.jeso,

To make it more clear, can you please draft that section of the circuit (basically, what goes into Opamp and the output transistor and LED)?

/odissey1

0 Likes
Vison_Zhang
Moderator
Moderator
Moderator
First comment on KBA 750 replies posted 250 sign-ins

If the output pin is the dedicate output pin of Opamp, then there have no analog switch between opamp output and pin internally, it is directly connection inside, so you have to use stop() api.

BTW, Why you use a analog pin to drive a led, i don't understand.

0 Likes
Len_CONSULTRON
Level 9
Level 9
Beta tester 500 solutions authored 1000 replies posted

Hi,

It appears you are trying to drive the LED to control its intensity.  However to control intensity as an analog signal you need to control the drive current.  Voltage control of intensity is very problematic. This is because the LED which is a diode, has a very narrow voltage range where LED is full OFF or full ON.  For a standard red LED, that is basically <1.5 for OFF and >2.4V for ON.    Due to temperature effects (LED heat-up) and manufacturing process variations, using Voltage control is difficult to keep a consistent intensity.   The intensity to voltage relationship is definitely not linear.

If you must use analog to drive to an LED, there is a simple circuit to drive the LED with a settable constant current.  Since there is a near-linear relationship between intensity and current, this is a much better control circuit.  It also can prevent overdriving the LED current to prevent LED destruction and thermal runaway effects.  If you're interested, I can provide one.

A much better way to control LED intensity that is commonly used is to drive the LED through a current limiting resistor using a digital PWM output.  It saves on precious internal PSoC resources.  By controlling the PWM duty cycle, the integrity can be controlled without a feedback loop from the LED circuit.  Turning OFF or ON the LED using this method, is simple.  Just _Start() or _Stop() the PWM component.

To answer your original question directly, there are potentially multiple ways to switch the LED output ON or OFF.

  • As hinted by another user, Use LED_OPAMP_Stop() API call.
  • Set the drive mode of LED_OPAMP_OUT to digital output low to turn OFF the LED using
    • LED_OUTPUT_OUT_Write(0);   // set the pin digital output value to low (0).
    • LED_OUTPUT_OUT_SetDriveMode(Pin_DM_STRONG);   // change pin from analog Hi-z to digital output strong.  With the digital out value set to 0, the output will be low.
  • Set the drive mode of LED_OPAMP_OUT to analog Hi-z to turn ON the LED using
    • LED_OUTPUT_OUT_SetDriveMode(Pin_DM_ALG_HIZ);   // change pin to analog Hi-z.

There are other more obscured ways of controlling the ON/OFF of the LED output.  They should be used only under special circumstances.

Len

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

Thank you all for the answers. I don't know why but I know it has to be like this. The opamp is there to even out the negative effects on the current.

If there is no other option with this hw configuration to control the output of opamp by digital signal, then i will use the opamp start and stop api.

I just thought that maybe there is a better option than to turn the whole opamp on and off.

0 Likes