Pages: [1]   Go Down
Author Topic: Changing PWM that are on Different Timers  (Read 521 times)
0 Members and 1 Guest are viewing this topic.
London, ON
Offline Offline
Jr. Member
**
Karma: 0
Posts: 71
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello,

I am trying to change the PWM frequency on some of the pins that are not on a PWM timer.

Looking at the variant.cpp file, (portion shown below)
Code:
  // 2
  { PIOB, PIO_PB25B_TIOA0,   ID_PIOB, PIO_PERIPH_B, PIO_DEFAULT, (PIN_ATTR_DIGITAL|PIN_ATTR_TIMER), NO_ADC, NO_ADC, NOT_ON_PWM,  TC0_CHA0     }, // TIOA0
  { PIOC, PIO_PC28B_TIOA7,   ID_PIOC, PIO_PERIPH_B, PIO_DEFAULT, (PIN_ATTR_DIGITAL|PIN_ATTR_TIMER), NO_ADC, NO_ADC, NOT_ON_PWM,  TC2_CHA7     }, // TIOA7
  { PIOC, PIO_PC26B_TIOB6,   ID_PIOC, PIO_PERIPH_B, PIO_DEFAULT, (PIN_ATTR_DIGITAL|PIN_ATTR_TIMER), NO_ADC, NO_ADC, NOT_ON_PWM,  TC2_CHB6     }, // TIOB6

  // 5
  { PIOC, PIO_PC25B_TIOA6,   ID_PIOC, PIO_PERIPH_B, PIO_DEFAULT, (PIN_ATTR_DIGITAL|PIN_ATTR_TIMER), NO_ADC, NO_ADC, NOT_ON_PWM,  TC2_CHA6     }, // TIOA6
  { PIOC, PIO_PC24B_PWML7,   ID_PIOC, PIO_PERIPH_B, PIO_DEFAULT, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM),   NO_ADC, NO_ADC, PWM_CH7,     NOT_ON_TIMER }, // PWML7
  { PIOC, PIO_PC23B_PWML6,   ID_PIOC, PIO_PERIPH_B, PIO_DEFAULT, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM),   NO_ADC, NO_ADC, PWM_CH6,     NOT_ON_TIMER }, // PWML6
  { PIOC, PIO_PC22B_PWML5,   ID_PIOC, PIO_PERIPH_B, PIO_DEFAULT, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM),   NO_ADC, NO_ADC, PWM_CH5,     NOT_ON_TIMER }, // PWML5
  { PIOC, PIO_PC21B_PWML4,   ID_PIOC, PIO_PERIPH_B, PIO_DEFAULT, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM),   NO_ADC, NO_ADC, PWM_CH4,     NOT_ON_TIMER }, // PWML4
  // 10
  { PIOC, PIO_PC29B_TIOB7,   ID_PIOC, PIO_PERIPH_B, PIO_DEFAULT, (PIN_ATTR_DIGITAL|PIN_ATTR_TIMER), NO_ADC, NO_ADC, NOT_ON_PWM,  TC2_CHB7     }, // TIOB7
  { PIOD, PIO_PD7B_TIOA8,    ID_PIOD, PIO_PERIPH_B, PIO_DEFAULT, (PIN_ATTR_DIGITAL|PIN_ATTR_TIMER), NO_ADC, NO_ADC, NOT_ON_PWM,  TC2_CHA8     }, // TIOA8
  { PIOD, PIO_PD8B_TIOB8,    ID_PIOD, PIO_PERIPH_B, PIO_DEFAULT, (PIN_ATTR_DIGITAL|PIN_ATTR_TIMER), NO_ADC, NO_ADC, NOT_ON_PWM,  TC2_CHB8     }, // TIOB8

Notice how only channels 6, 7, 8 and 9 have the tag "PWM_CH#".  From my understanding and observations, these pins are dynamic and you are able to change the PWM frequencies of these channels, using the follow portion in variant.h

Code:
/*
 * PWM
 */
#define PWM_INTERFACE PWM
#define PWM_INTERFACE_ID ID_PWM
#define PWM_FREQUENCY 33000
#define PWM_MAX_DUTY_CYCLE 255
#define PWM_MIN_DUTY_CYCLE 0
#define PWM_RESOLUTION 8

Notice that I changed the PWM frequency of the mentioned pins to 33K.

The problem is that this timer only effects channels 6, 7, 8 and 9. 

My concern is, how can I change the other pins?  I want to be able to change the PWM frequencies of channels 11, 3 and 5.  If anyone can help me out with this issue, it is much appreciated.

Thanks,
Daniel
Logged

Dialup is the future.

London, ON
Offline Offline
Jr. Member
**
Karma: 0
Posts: 71
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I found a solution, not the greatest and most efficient but it works.

If you are using other PWM pins that aren't 6, 7, 8 or 9 - and want to change the frequency, you can also change the TC timer in the variant.h file.

The SAM is fully customizable and we should be able to change each of the 9 (I believe) timers on the Arduino without changing a bundle of them.

Nevertheless, its solved smiley-grin

Daniel
Logged

Dialup is the future.

Pages: [1]   Go Up
Jump to: