Pages: 1 2 [3] 4 5   Go Down
Author Topic: DUE PWM Frequency  (Read 19339 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
God Member
*****
Karma: 26
Posts: 606
Always making something...
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Offline Offline
Full Member
***
Karma: 1
Posts: 124
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi there


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

thanks in advance
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 24
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Offline Offline
Full Member
***
Karma: 1
Posts: 124
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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


Do you know how to generate a SINE PWM ?
Logged

Germany
Offline Offline
Full Member
***
Karma: 10
Posts: 230
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Offline Offline
Full Member
***
Karma: 1
Posts: 124
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


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
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 24
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Offline Offline
Full Member
***
Karma: 1
Posts: 124
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi what about my question smiley-sad how can I modify thisd code to get a SINE PWM wave ?
Logged

0
Offline Offline
God Member
*****
Karma: 26
Posts: 606
Always making something...
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

What exactly is a "SINE PWM" wave?
Logged

Offline Offline
Full Member
***
Karma: 1
Posts: 124
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

0
Offline Offline
God Member
*****
Karma: 26
Posts: 606
Always making something...
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Offline Offline
Full Member
***
Karma: 1
Posts: 124
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

wow this sounds good. Do you have a link ?
Logged

0
Offline Offline
God Member
*****
Karma: 26
Posts: 606
Always making something...
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Offline Offline
Full Member
***
Karma: 1
Posts: 124
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

0
Offline Offline
God Member
*****
Karma: 26
Posts: 606
Always making something...
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Pages: 1 2 [3] 4 5   Go Up
Jump to: