to generate pwm

I am using arduino uno r3 board. As per the specifications of the board pwm outputs can be obtained on pin no:3,5,6,9,10,11. I have written the code below but i am able to obtain pwm output at only pin no:9,10 and 11, rest three pins(pin no: 3,5,6) have no output. I am changing the duty cycle of the pwm by potentiometer at A0 Is there some problem with the code?

int poten = A0;
int pwm1 = 3;
int pwm2 = 5;
int pwm3 = 6;
int pwm4 = 9;
int pwm5 = 10;
int pwm6 = 11;
int val=0;

void setup() {
  pinMode(pwm1, OUTPUT);
  pinMode(pwm2, OUTPUT);
  pinMode(pwm3, OUTPUT);
  pinMode(pwm4, OUTPUT);
  pinMode(pwm5, OUTPUT);
  pinMode(pwm6, OUTPUT);


void loop() {
analogWrite(pwm1, 175); //mapping 0-1023; 0-255;
analogWrite(pwm2, 175);
analogWrite(pwm3, 175);
analogWrite(pwm4, val/4);
analogWrite(pwm5, val/4);
analogWrite(pwm6, val/4);

analogWrite(pwm1, val/4); analogWrite(pwm2, val/4); analogWrite(pwm3, val/4);

the three commands in above code have to be replaced by these three. Sorry for the inconvenience.

Try a short delay before writing new pwm-values

What are you using to indicate if there's output or not?

Actually i have simulated it on proteus. In proteus i have used an oscilloscope to see the waveform.

knut_ny: Try a short delay before writing new pwm-values

I would not have thought that would be necessary but maybe the OP's code is writing the Timer registers so often that nothing useful gets done.

@neha7875 try putting delay(50); as the last thing in loop().

If that does not fix the problem then write a short test program with code in setup() that just does analogWrite() to one of the PWM pins and check that it works. Leave loop() empty. Then try that for each of the pins in turn - one at a time.


Does the problem reproduce on an actual Arduino?

Arduino simulators have a pretty poor reputation for not actually behaving like the real hardware.