Una duda, estoy probando la libreria <PWM.h> pero solo funciona con los pines 11 y 12, pero no con los demas, alguien le pasa lo mismo?
#include <PWM.h>
int32_t frecuencia =445; //he variado int32, 8 y 16
int tiempo =150;
unsigned long inicia =0;
int led =12; //en este y 11 perfecto en 6,7,8,9,10 no funciona
int brillo =0;
int fade =-1;
void setup()
{ InitTimersSafe();
bool suceso = SetPinFrequencySafe(led, frecuencia);
}
void loop()
{
pwmWrite(led, brillo);
if(millis()-inicia>=tiempo){
inicia=millis();
if((brillo==0)||(brillo==255)){
fade=-fade;
}brillo+=fade;
}
}
The Arduino has 3Timers and 6 PWM output pins. The relation between timers and PWM outputs is:
Pins 5 and 6: controlled by timer0
Pins 9 and 10: controlled by timer1
Pins 11 and 3: controlled by timer2
On the Arduino Mega we have 6 timers and 15 PWM outputs:
Pins 4 and 13: controlled by timer0
Pins 11 and 12: controlled by timer1
Pins 9 and10: controlled by timer2
Pin 2, 3 and 5: controlled by timer 3
Pin 6, 7 and 8: controlled by timer 4
Pin 46, 45 and 44:: controlled by timer 5
Si usas Timer0 modificas millis()
Veo comandos para cada timer en tu librería, mira los ejemplos.
La librería en un ejemplo dice:
float GetPinResolution(uint8_t pin)
Returns the same value as TimerX_GetResolution(), but takes a pin number
as a parameter so that the caller is timer agnostic.
There are several things to keep in mind when trying to optimize resolution:
-pwmWriteHR() is only useful for 16 bit timers, since 8 bit timers are inherently limited to 8 bit pwm
-The higher the frequency, the lower the resolution. pwmWriteHR() will automatically map input to the
actual timer resolution
-Resolution can be optimized in this way for 2 pins on the Uno (9 and 10), and 11 pins on the Mega (2,
3, 5, 6, 7, 8, 11, 12, 44, 45, and 46)