Go Down

Topic: PWM output voltage issues (Read 887 times) previous topic - next topic


Hey guys, I've used code to change the frequency of one of my PWM pins to 95 khz and now I'm experiencing issues with the output voltage.  I expected the output voltage to be 5v and 0v but I'm actually getting +50mv and -50 mv.  Does anyone know how to fix this? I need to have 5v output.

This is the code I used:
Code: [Select]
#define outpin 10                                  // OC2A pin - cannot be changed
#define clockFrequency 16000000                    // Arduino clock frequency
#define outputFrequency 95000                    // desired output frequency
#define prescaleFactor 1                           // the only choice to get 1 MHz out

void setup ()
  TCCR2B = B00000001;                               // set CS20, clear CS21, CS22 and WGM22
  TCCR2A = B01000010;                               // set COM2A0 and WGM21, clear COM2A1 and WGM20

  OCR2A  = ((float)clockFrequency / (outputFrequency * 2 * prescaleFactor)) -1;  // timer data

  pinMode(outpin, OUTPUT);                          // turn on output pin   

// the timer runs with no additional code and no use of interrupts
// do whatever else you want to do here


void loop ()
// do whatever else you want to do here


but I'm actually getting +50mv and -50 mv.

No you are not.
It is probably an artifact of how you are measuring it.
What are you doing to measure it?


I actually fixed it, you were right, I was measuring it wrong.  Thanks for the reply!

Go Up