Pwm wave (not getting amplitude of 5v)

Hello, i am trying to generate PWM wave of frequency 5kHz and duty cycle of 70% but he problem is when i am viewing the output signal in proteus using oscilloscope, the max output is 1.35v and min -3.5v whereas it should be 5v and 0v.
The code is mentioned below

#include <TimerOne.h>

const int ledPin = 10;
const int inPin = 3;
void setup() {
  Serial.begin(9600);
  pinMode(ledPin, OUTPUT);
  pinMode(inPin, INPUT);
  Timer1.initialize(20000); 
  Timer1.pwm(ledPin, 717);  // Set PWM duty cycle to 50% (out of 1023)
}

void loop() {
  int pwmValue = (analogRead(inPin));
  Serial.println(pwmValue);

}

An Arduino GPIO pin cannot output a negative voltage. Noting that the total voltage swing that you are seeing is nearly 5V, what are you using as your GND reference for the oscilloscope probes ?

1 Like

this is the circuit,the gnd and the input voltage are already set by default

My guess is that you have your oscilloscope's Y amplifier set to AC coupling. You need to have it on DC coupling.

By definition, a range of -3.5 to +1.5 is an amplitude of 5. Is there an offset applied in your simulation somewhere?

Anyhow, the important question is this: what do you get when you try it with real hardware? If you get -3.5V to 1.5V there that would be very interesting...

Yeah,this was the issue.I thought i already had set it to DC.Thanks alot everyone though

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.