Go Down

Topic: DUE PWM Frequency (Read 23 times) previous topic - next topic

Paul Stoffregen

It's unfortunate these new API ideas, which have been agreed upon in principle (usually after much conversation on the developer mail list) don't get implemented or even documented in the official Arduino software.

If this had been a documented part of the API, even as "coming in a future version", odds are good Intel would have incorporated variable frequency into their I/O scheme on the new Galileo board.  Looking through their code, it seems they did special support for the pulse generation for Servo.

Then again, I could do far better at documenting stuff for Teensy.  Maybe next year I ought to slow down on the tech side and focus on that?

so3ody

Hi there


can you please post your software with the 3 sinwaves  as an output

thanks in advance

earx

to change the PWM frequency of all pins.. that means also the ones not in range 6,7,8,9.. you should change also TC_FREQUENCY in variant.h.

this works perfectly. i get a nice 330 kHz period for all pins now.

so3ody

Hi check the pwm01.h you can change the PWM frequency with it


Do you know how to generate a SINE PWM ?

Markus_L811


to change the PWM frequency of all pins.. that means also the ones not in range 6,7,8,9.. you should change also TC_FREQUENCY in variant.h.

this works perfectly. i get a nice 330 kHz period for all pins now.

How did you do it in detail?

so3ody


void setup()
{
 
 
// PWM Pulsbreite eingeben
    uint32_t  pwm_duty_u=  0.75*65536;//2^16 =65536 also maximaler Wert fuer duty cycle ist 65536-1
    uint32_t  pwm_duty_v=  0.75*65536;
    uint32_t  pwm_duty_w=  0.75*65536;
   
   
   
// PWM Frequenz in HZ eingeben
   
    uint32_t  pwm_freq1 =  300000; 
   
//PWM Auflösung

    pwm_set_resolution(16); 
   
   
   
//Hardware Ausgabe

    pwm_setup( 7, pwm_freq1, 2);  //pwm_setup (pin,freq,iclock 2 ist Clock B)
    pwm_setup( 8, pwm_freq1, 2); 
    pwm_setup( 9, pwm_freq1, 2); 
     
   
   
    pwm_write_duty( 7, pwm_duty_u ); // pin, duty_cycle_pro_phase
    pwm_write_duty( 8, pwm_duty_v ); 
    pwm_write_duty( 9, pwm_duty_w ); 


// Verzögerung in uS

delay(30000); 
       
// PWM Stop

   // pwm_stop( 7 );
    //pwm_stop( 8 );
    //pwm_stop( 9 );


the header file pwm01.h  is here :http://forum.arduino.cc/index.php?PHPSESSID=povm0bi5ipfp6s6o33a226h4s0&topic=144446.msg1149044#msg1149044

earx

in variant.h:
change the line:

#define TC_FREQUENCY        1000

to

#define TC_FREQUENCY        300000

and as said previously:

#define PWM_FREQUENCY           1000

to

#define PWM_FREQUENCY           300000

the frequency doesn't have to match exactly. it's governed by the mother clock divided by the pwm resolution (256 steps) divided by a power of two. the max would be 84 MHz / 256 = 328.125 kHz.

hope that clears things up. there could be more elegant ways and i still have to test what this does to micros() and delay().. on AVR-based Arduino that issue exists.

so3ody

Hi what about my question :( how can I modify thisd code to get a SINE PWM wave ?

Paul Stoffregen

What exactly is a "SINE PWM" wave?

so3ody

This is a sine pwm

http://www.pstracks.com/wp-content/uploads/2012/12/fig4.gif

It enabels you to re build a sine wave throught your pwm signal

Paul Stoffregen

The PWM output object on the (currently beta test) Teensy audio library supports this.

so3ody

wow this sounds good. Do you have a link ?

Paul Stoffregen

I should mention this works on Teensy 3.1, but hasn't been ported to Arduino Due (and may never work on Due, since Due has the Cortex-M3 chip and a lot of this code depends on the DSP extensions on Cortex-M4).  With that caveat in mind, here's the link.

https://github.com/PaulStoffregen/Audio

To get a sine wave, you'd write a sketch with an AudioSynthWaveform object, an AudioOutputPWM object, and one AudioConnection object to feed the sine wave from the synth to the pwm.

so3ody

F*** thisa sounds complicated...I actually need it to  drive an H bridge..

Paul Stoffregen

Are you now saying you need two PWM outputs, with some special timing relationship to each other?

Go Up