non serve utilizzare l'assembler, da Arduino è possibile controllare direttamente i registri dei timer associando i valori che servono. A titolo di esempio, questa è la parte di codice che nel ELS si incarica di configurare il Timer1 in modalità PWM:
Codice: Seleziona tutto
void SetPWM() //Sets the PWM and starts Timer1
{
ICR1 = 65535; //(65535)set TOP at maximum value in order to get minumun frequency on the motor with prescaler clk/64
OCR1A = 3; // Set OCR1A register to 3 which means that the CLEAR of the OC1A pin is done after 3 timer1 ticks.
// means 12us with clk/64 prescaler
TCCR1A = _BV(COM1A1) | _BV(WGM11); //OC1A (pin 9) set for PWM with SET at BOTTOM and CLEAR at MATCH (non-inverted mode)
TCCR1B = _BV(WGM13) | _BV(WGM12); //WGM set for Fast PWM with ICR1 used as TOP value
}Cioè, in pratica, sul datasheet devi capire come impostare i registri del timer in base alla configurazione che vuoi implementare e poi assegni i valori ai registri semplicemente come fatto qui sopra nel codice.
