Getting wrong result from PWM

I am a new student and recently started on a new project and I got a duty cycle of 100% despite the controller produced an negative value.

Any suggestions to fix this issue such that my duty cycle will be 0 when controller produced an negative value.

What is the code?
Can you explain better that thing of "the controller produced an negative value"?

Never apply a negitave voltage to the input of an arduino, you will damage it.

Hi, can you please post your code and a diagram of how you are measuring the PWM output.
A CAD or a picture of a hand drawn circuit in jpg, png or pdf will be fine.

Hope to help..

Tom... :slight_smile:

Hi.

You could set up a threshold so that when it hits the negative value, it automatically switches the duty cycle to 0% instead of 100%.

Cheers. :slight_smile:

Not clear to me if this "controller" is the Arduino or another device connected to it?

I got a duty cycle of 100% despite the controller produced an negative value.

Looks like a classic case of GIGO.

I was sure I had replied to this earlier today - but I must have consigned it to the ether.

You need to check the value before using it with analogWrite. For example

if (x < 0) {
   x = 0;
}
analogWrite(x);

...R