Go Down

### Topic: simple PWM frequency sweep from 1Hz to 4MHZ - i´m stuck in Nano code (Read 968 times)previous topic - next topic

#### gibrancurtiss

##### Jun 15, 2018, 02:27 am
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

#### ard_newbie

#1
##### Jun 15, 2018, 05:14 amLast Edit: Jun 15, 2018, 07:51 am by ard_newbie
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.

#### gibrancurtiss

#2
##### Jun 15, 2018, 01:21 pm
Hi ard_newbie

This is a great example, i'll try today :-)

#### gibrancurtiss

#3
##### Jun 15, 2018, 01:47 pmLast Edit: Jun 15, 2018, 02:35 pm by gibrancurtiss
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

Code: [Select]
`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);               }}`

#### ard_newbie

#4
##### Jun 15, 2018, 02:38 pm

What don't you understand ?

#### gibrancurtiss

#5
##### Jun 15, 2018, 02:41 pm
What I have to put inside the loop to update the freqs.

#### gibrancurtiss

#6
##### Jun 16, 2018, 11:41 pm
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!!!!!

Go Up