PWM Code not Outputting Expected Values


hi,
i trying write code changes duty cycle of each pulse 25%. fading example without delay @ end , different frequency. when test code using oscilloscope pulses change duty cycle properly. i'm not sure if wrote code wrong or not, can help! here code:

code: [select]
/*
this code designed output square wave @ 60 hz on pins 5 , 6
date: march 19, 2014
authour: edward white
version: 2
*/

int p1 = 3;        //pin 3 first output
int p2 = 9;        //pin 9 second output


// setup routine runs once when press reset:
void setup()  {
  //declare pin 3 , 9 outputs
  pinmode(p1,output);
  pinmode(p2,output);
  // set output frequency 490.2 hz
  tccr1b = tccr1b & 0b11111000 | 0x03;
  tccr2b = tccr2b & 0b11111000 | 0x04;
}

// loop routine run forever:
void loop()  {
  //increase pin 3 0 98.8% duty cycle:
  for(int dutycycle = 0 ; dutycycle <=252; dutycycle +=63){
    // sets value  (range 0 252):
    analogwrite(p1, dutycycle);
  }
  // decrease pin 3 98.8% 0% duty cycle:
  for(int dutycycle = 252 ; dutycycle >=0; dutycycle -=63) {
    //sets value (range 252 0):
    analogwrite(p1, dutycycle);
  }
  //increase pin 9 0% 98.8% duty cyle:
  for(int dutycycle = 0 ; dutycycle <=252; dutycycle +=63){
    // sets value (range 0 252):
    analogwrite(p2, dutycycle);
  }
  // decrese pin 9 98.8% 0% dutycycle:
  for(int dutycycle = 252 ; dutycycle >=0; dutycycle -=63) {
    //sets value (range 252 0)
    analogwrite(p2, dutycycle);
  }
}
 


i'm not getting errors when verify code.
thanks,
ed


when test code using oscilloscope pulses change duty cycle properly.


if word "to" should "do"then sounds program working properly.

but guess not or wouldn't posting here. problem?

...r


Arduino Forum > Using Arduino > Programming Questions > PWM Code not Outputting Expected Values


arduino

Comments

Popular posts from this blog

VIDIOC_S_FMT error 16, Device or resource busy - Raspberry Pi Forums

using a laptop skeleton to build a pi laptop - Raspberry Pi Forums

Forum for Joomla? - Joomla! Forum - community, help and support