simple PWM frequency sweep from 1Hz to 4MHZ - i´m stuck in Nano code

Hello guys.

I´ve a code on Nano that works great but I cant figure out how to code on DUE.
I need a PWM (50% duty) sweep from 1hz to 4MHz with 150 to 200 steps.
Any help ?

Thank you

There are numerous example sketches of PWM programming in the DUE forum, e.g. this one, reply #4:

https://forum.arduino.cc/index.php?topic=396125.0

To output a PWM pulse signal (at 50% duty cycle) with a good continuity between 1 Hz and 4 MHz, you would rather want using SysTick Timer Counter for half periods below 1 ms, and the PWM controller for half periods above 1 ms to set/clear a pin with PIO_SODR/PIO_CODR.

Hi ard_newbie

Thank you for your reply.
This is a great example, i'll try today :slight_smile:

Hi again !

I cant make the sketch work.
This is the original Nano code on pin 9 , could you help me a little ?
The code will run on a synthesizer. I´ll give you the credits to the lines

Thank you

void setup(){

 TCCR1A  = 0b10000010; 
 TCCR1B  = 0b00011001; 
 ICR1    = 110;
 OCR1A   = 55;
}

void loop(){

 for (unsigned int frequencyIndex = 0 ; frequencyIndex < ENDFREQ ; frequencyIndex++) {
   CLR(TCCR1B, 0);        
   TCNT1     = 0;                      
   ICR1      = frequencyIndex;   
   OCR1A     = frequencyIndex >> 1;   
   SET(TCCR1B, 0);               
}
}

What don't you understand ?

What I have to put inside the loop to update the freqs.

Hi ard_newbie!

Found a solution , now have to search the frquencies I need!

https://forum.arduino.cc/index.php?topic=420674.0
#10

Thank you!!!!!