Very simple code issue on DUE

This code

void setup() 
{
  pinMode(12, OUTPUT);
  Serial.begin(9600);
  Serial.print("test");
}

void loop() 
{
  analogWrite(12, 1);
  delayMicroseconds(500);
  analogWrite(12, 255);
  delayMicroseconds(500);
}

produces attached scope output, WHY :o ?

I am sure it's a simple answer :wink:

Steve

Yep looks good check the freq of the PWM you are using!

Mark

check the freq of the PWM you are using!

If it's compatible with the AVR, the PWM frequency is about 1kHz. So delaying 500us between calls to analogWrite() will interrupt/reset the PWM (or something) before even one cycle has completed. I don't think it's 'defined' what happens in that case, and it doesn't surprise me that it's weird.

OK think I am starting to understand, has anyone got a good example of how to set a LED brightness and then change it without causing a reset etc.

What I want to do it pulse the LED as fast as possible and with different brightness's

So this sort of thing, output these brightness's as quickly as possible

1%
50%
34%
2%
95%
25%

Thanks

Steve

Sorted bit banging it :slight_smile:

Thx

Steve