SAMD21J18A, can not change PWM duty cycle dynamically on TC timer

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

Hi All

 

I am using the SAMD21J18A.

 

I have four PWM signals being outputted on PINS PB16,PB17,PA20,PA21, which are TC6 and TC7 output 0 and 1.

 

I can initially set the duty cycle, but when I try to change the value in my application, it makes no change. This is my code below.

 

What am i doing wrong?

 

struct tc_module tc_instance;
struct tc_config config_tc;
struct tc_module tc_instanceb;
struct tc_config config_tcb;
void configure_tc_LED(uint16_t r,uint16_t g,uint16_t b,uint16_t w)
{
	
	//struct tc_config config_tc;
	tc_get_config_defaults(&config_tc);
	config_tc.counter_size    = TC_CTRLA_MODE_COUNT16;
	config_tc.wave_generation = TC_WAVE_GENERATION_NORMAL_PWM;
	config_tc.counter_16_bit.compare_capture_channel[0] = r;
	config_tc.counter_16_bit.compare_capture_channel[1] = g;
	config_tc.pwm_channel[0].enabled = true;
	config_tc.pwm_channel[0].pin_out = PIN_PB16E_TC6_WO0;
	config_tc.pwm_channel[0].pin_mux = MUX_PB16E_TC6_WO0;
	config_tc.pwm_channel[1].enabled = true;
	config_tc.pwm_channel[1].pin_out = PIN_PB17E_TC6_WO1;
	config_tc.pwm_channel[1].pin_mux = MUX_PB17E_TC6_WO1;
	tc_init(&tc_instance, TC6, &config_tc);
	tc_enable(&tc_instance);
	
	//struct tc_config config_tcb;
	tc_get_config_defaults(&config_tcb);
	config_tcb.counter_size    = TC_CTRLA_MODE_COUNT16;
	config_tcb.wave_generation = TC_WAVE_GENERATION_NORMAL_PWM;
	config_tcb.counter_16_bit.compare_capture_channel[0] = b;
	config_tcb.counter_16_bit.compare_capture_channel[1] = w;
	config_tcb.pwm_channel[0].enabled = true;
	config_tcb.pwm_channel[0].pin_out = PIN_PA20E_TC7_WO0;
	config_tcb.pwm_channel[0].pin_mux = MUX_PA20E_TC7_WO0;
	config_tcb.pwm_channel[1].enabled = true;
	config_tcb.pwm_channel[1].pin_out = PIN_PA21E_TC7_WO1;
	config_tcb.pwm_channel[1].pin_mux = MUX_PA21E_TC7_WO1;
	tc_init(&tc_instanceb, TC7, &config_tcb);
	tc_enable(&tc_instanceb);	
}

Thanks

This topic has a solution.

Thanks

Regards

DJ

Last Edited: Fri. May 28, 2021 - 04:04 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

djoshi wrote:
but when I try to change the value in my application, it makes no change.

If this is what you have a problem with why not show the code you have tried?

tc_set_compare_value

Is what I expect you should call.

/Lars

 

This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The code is shown in my first post, but i have now found that i need to do the following

tc_set_compare_value(&tc_instanceb, TC_COMPARE_CAPTURE_CHANNEL_1, 35000);	

 

The issue is solved now.

Thanks

Regards

DJ