Lien de référence que j'ai trouvé :
https://forum.arduin...?topic=420674.0
avec en particulier ce code d'exemple à tester :
// --------------------------------------------
//
// PWM with timers demo
//
// Bob Cousins, August 2014
// --------------------------------------------
typedef struct {
Tc *pTC; // TC0, TC1, or TC2
byte channel; // 0-2
byte output; // 0 = A, 1 = B
} tTimerInfo;
tTimerInfo timerLookup [] =
{
{NULL,0,0}, // 0
{NULL,0,0},
{TC0,0,0}, // pin 2 = TIOA0
{TC2,1,0}, // pin 3 = TIOA7
{TC2,0,1}, // pin 4 = TIOB6
{TC2,0,0}, // pin 5 = TIOA6
{NULL,0,0},
{NULL,0,0},
{NULL,0,0},
{NULL,0,0},
{TC2,1,1}, // pin 10 = TIOB7
{TC2,2,0}, // pin 11 = TIOA8
{TC2,2,1}, // pin 12 = TIOB8
{TC0,0,1} // pin 13 = TIOB0
};
/**
* \brief set a pin for PWM using a timer channel
* \param pin pin to use (0-13 only!)
* \param frequency the frequency
* \param dutyCyle duty cycle 0-255
* \return this function returns a count, which is the effective PWM resolution. Returns 0 if pin is not valid
*/
uint32_t setupTimerPwm (byte pin, uint32_t frequency, unsigned dutyCycle)
{
uint32_t count = VARIANT_MCK/2/frequency;
tTimerInfo *pTimer = &timerLookup[pin];
if (pTimer != NULL)
{
TC_SetRC (pTimer->pTC, pTimer->channel, count);
if (pTimer->output == 0)
TC_SetRA (pTimer->pTC, pTimer->channel, count * dutyCycle / 256);
else
TC_SetRB (pTimer->pTC, pTimer->channel, count * dutyCycle / 256);
return count;
}
else
return 0;
}
void setup() {
// put your setup code here, to run once:
// use the Arduino lib to do initial setup
analogWrite (2, 128);
analogWrite (13, 128);
analogWrite (5, 128);
analogWrite (4, 128);
analogWrite (3, 128);
analogWrite (10, 128);
analogWrite (11, 128);
analogWrite (12, 128);
// pins 2 and 3 share the same timer so must have same frequency
setupTimerPwm (2, 2000, 128);
setupTimerPwm (13, 2000, 64);
// pins 5 and 4 share the same timer
setupTimerPwm (5, 3000, 128);
setupTimerPwm (4, 3000, 64);
// pins 3 and 10 share the same timer
setupTimerPwm (3, 4000, 128);
setupTimerPwm (10, 4000, 64);
// pins 11 and 12 share the same timer
setupTimerPwm (11, 5000, 128);
setupTimerPwm (12, 5000, 64);
}
void loop() {
// put your main code here, to run repeatedly:
}
On notera en particulier que les pins partagent les même timer par paires.
(2, 13) => Timer 0
(5, 4); => Timer 6
(3, 10) => Timer 7
(11,12, ) => Timer 8
... et donc auront nécessairement la même fréquence ( une seule même fréquence pour chaque paire )