SAMD21 multiple PWM using ASF

Go To Last Post
9 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello to all,

I'm trying to configure multiple PWM output using ASF. I need 8 PWM output.

 

I started using the basic TCC Callback example, modifying it to manage the 8 output, but I only get PWM one at a time, or two from pin with different TCC.

 

Is there a way to configure multiple PWM using ASF?

 

Many Thanks

Clemente

Last Edited: Sun. Feb 12, 2017 - 07:00 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yes it is possible but to get 8 outputs you will have to use all 3 TCC instances (it's the number of compare channels that is significant and they have 4, 2 and 2).

 

#include <asf.h>

static void configure_tcc(void);

struct tcc_module tcc_instance;
struct tcc_module tcc_instance1;
struct tcc_module tcc_instance2;

static void configure_tcc(void)
{
    struct tcc_config config_tcc;
    
    tcc_get_config_defaults(&config_tcc, TCC0);
    config_tcc.counter.period = 0x1FF;
    config_tcc.compare.wave_generation = TCC_WAVE_GENERATION_SINGLE_SLOPE_PWM;
    config_tcc.compare.match[0] = 0x23;
    config_tcc.compare.match[1] = 0x33;
    config_tcc.compare.match[2] = 0x43;
    config_tcc.compare.match[3] = 0x53;
    
    config_tcc.pins.enable_wave_out_pin[0] = true;
    config_tcc.pins.wave_out_pin[0]        = PIN_PA04E_TCC0_WO0;
    config_tcc.pins.wave_out_pin_mux[0]    = MUX_PA04E_TCC0_WO0;
    
    config_tcc.pins.enable_wave_out_pin[1] = true;
    config_tcc.pins.wave_out_pin[1]        = PIN_PA05E_TCC0_WO1;
    config_tcc.pins.wave_out_pin_mux[1]    = MUX_PA05E_TCC0_WO1;
    
    config_tcc.pins.enable_wave_out_pin[2] = true;
    config_tcc.pins.wave_out_pin[2]        = PIN_PA10F_TCC0_WO2;
    config_tcc.pins.wave_out_pin_mux[2]    = MUX_PA10F_TCC0_WO2;
    
    config_tcc.pins.enable_wave_out_pin[3] = true;
    config_tcc.pins.wave_out_pin[3]        = PIN_PA11F_TCC0_WO3;
    config_tcc.pins.wave_out_pin_mux[3]    = MUX_PA11F_TCC0_WO3;
    
    tcc_init(&tcc_instance, TCC0, &config_tcc);
    
    tcc_get_config_defaults(&config_tcc, TCC1);
    config_tcc.counter.period = 0x1FF;
    config_tcc.compare.wave_generation = TCC_WAVE_GENERATION_SINGLE_SLOPE_PWM;
    config_tcc.compare.match[0] = 0x63;
    config_tcc.compare.match[1] = 0x73;
    
    config_tcc.pins.enable_wave_out_pin[0] = true;
    config_tcc.pins.wave_out_pin[0]        = PIN_PA06E_TCC1_WO0;
    config_tcc.pins.wave_out_pin_mux[0]    = MUX_PA06E_TCC1_WO0;
    
    config_tcc.pins.enable_wave_out_pin[1] = true;
    config_tcc.pins.wave_out_pin[1]        = PIN_PA07E_TCC1_WO1;
    config_tcc.pins.wave_out_pin_mux[1]    = MUX_PA07E_TCC1_WO1;
    
    tcc_init(&tcc_instance1, TCC1, &config_tcc);
    
    tcc_get_config_defaults(&config_tcc, TCC2);
    config_tcc.counter.period = 0x1FF;
    config_tcc.compare.wave_generation = TCC_WAVE_GENERATION_SINGLE_SLOPE_PWM;
    config_tcc.compare.match[0] = 0x83;
    config_tcc.compare.match[1] = 0x93;
    
    config_tcc.pins.enable_wave_out_pin[0] = true;
    config_tcc.pins.wave_out_pin[0]        = PIN_PA12E_TCC2_WO0;
    config_tcc.pins.wave_out_pin_mux[0]    = MUX_PA12E_TCC2_WO0;
    
    config_tcc.pins.enable_wave_out_pin[1] = true;
    config_tcc.pins.wave_out_pin[1]        = PIN_PA13E_TCC2_WO1;
    config_tcc.pins.wave_out_pin_mux[1]    = MUX_PA13E_TCC2_WO1;
    
    tcc_init(&tcc_instance2, TCC2, &config_tcc);
    
    tcc_enable(&tcc_instance);
    tcc_enable(&tcc_instance1);	
    tcc_enable(&tcc_instance2);	
}

int main(void)
{
    system_init();
    configure_tcc();
    while(1);
}

/Lars

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello Lajon,

many thanks for your responce.

 

Lajon wrote:

Yes it is possible but to get 8 outputs you will have to use all 3 TCC instances (it's the number of compare channels that is significant and they have 4, 2 and 2).

/Lars

Ah! This was not clear to me. I have this pin assignement:
 

    PWM_OUT1 PA9  TCC1/WO[3]   CC1	0
    PWM_OUT2 PA8  TCC1/WO[2]   CC0	1
    PWM_OUT3 PA15 TCC0/WO[5]   CC1	2
    PWM_OUT4 PA20 TCC0/WO[6]** CC2	3
    PWM_OUT5 PA6  TCC1/WO[0]   CC0	4
    PWM_OUT6 PA7  TCC1/WO[1]   CC1	5
    PWM_OUT7 PB12 TCC0/WO[6]** CC2	6
    PWM_OUT8 PB13 TCC0/WO[7]   CC3	7

and if I undestand what you say, about the compare channel (4,2,2), I can't use four TCC1 channels concurrently.

I need to free 2 pins that route to TCC2, isn't it?

 

Thanks again for your time.

Clemente

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Right, you need to use TCC2 also.

/Lars

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks Lars.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Lajon/Lars,

 

Have you used the code posted above ( Wed. Feb 15, 2017 - 11:40 PM ) to produce PWM Wave-forms on multiple channels on same TCCx simultaneously?

 

I am using similar code; but when I enable Channel 1, Channel 0 stops. I can have two simultaneous wave-forms from TCC0 and TCC1.

 

C. Dicaprio, Did you get 8 simultaneous outputs working?

 

Thanks,

Betta

 

Betta

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yes it works, I would not post the code if it did not work.

SAMD21 8 pwm from TCC0,TCC1 and TCC2

/Lars

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello Lars,

 

I'm a bit confused as to what the Waveform output 5 to 8 do and how to use them. I need a total of 24 PWM (for driving 8 RGB LEDs). The Microchip selector tool lists a total of 24 PWM outputs, but I am not sure which pins to select to enable that.

Last Edited: Tue. Apr 3, 2018 - 04:51 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Lars,

Thank you very much!

Nick