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 ?
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...