At the end of the series of posts: "The AVR timers in five minutes," I present a simple spreadsheet (in OpenOffice.org Calc), which calculates the required values \u200b\u200bfor the configurations ; mode views.
Once you understand how to calculate with pencil and paper, the values \u200b\u200bof N (NA) to be loaded into registers, depending on the mode of the timer can be a useful computational tool to facilitate this work.
It is valid for the AVR MCU ATmegaxx8 (ATmega88/168/328) and - at the time - the only Timer1 (16bit) can be safely done better, so I would like gladly better and especially corrections.
Let's see how to use it.
cells with colored background are those in which the user must enter a variable.
The first variable request, for all modes of operation, the clock frequency (fc) of the system in MHz, in cell C3 (light blue background):
one cell appear lower on the clock period (Tc) in microseconds.
NORMAL MODE
On the left appear the various values time for each factor Prescaler
WAY CTC
the required time will be required T (cell F13, lime green background ) in seconds:
On the left you will see a table with the values \u200b\u200bof N calculated for each factor prescaler. The values \u200b\u200bthat are marked "NR" in red, are not usable because it can not be represented in the register of the timer, because they are more than the maximum (65535, mindful of +1) or lower than zero:
N non-integer values \u200b\u200b(decimal different from zero) are still reported, thus allowing full flexibility of choice in each case, if the approximate value to the next or previous.
WAY CTC in January WAVEFORMS
will be required here is the desired signal frequency (fs), in cell F3 olive green, expressed in Hertz:
On the left, you see the values \u200b\u200bof N For each factor k prescaler :
Any values \u200b\u200bthat are marked "NR" in red, are not usable because they can not be represented in the register of the timer, because they are more than the maximum (65535, mindful of +1) or lower than zero. Also for this mode of operation of the N non-integer values \u200b\u200b(decimal different from zero) are still reported, thus allowing full flexibility to choose whether to hint, whether or not to default or over the entire immediate vicinity.
FAST MODE PWM January WAVEFORMS
For this mode there is a first table containing all the fixed frequency, which can be obtained in the individual mode fixed (8, 9 and 10bit), for different values \u200b\u200bof prescaler (K ):
Below is a second table, which, however, shows the values \u200b\u200bof N and NA are required to generate a signal with rectangular a frequency fs and the desired duty cycle:
values \u200b\u200bthat are marked "NR" in red, can not be used because they are either N values \u200b\u200bthat can not be represented in the register of the timer, because they are more than the maximum (65535, mindful of +1) or because less than 3 (the minimum resolution variable 2bit, quindi il valore minimo è 3 - cfr. Datasheet) oppure perché il valore NA è negativo.
I valori N e NA non interi (cifra decimale diversa da zero) sono comunque riportati, lasciando dunque piena flessibilità di scelta se approssimare, o meno, per difetto o per eccesso all'intero immediatamente vicino.
Per popolare questa tabella ovviamente occorre definire la frequenza fs (in Hz) nella cella F41 (sfondo colore marrone chiaro) e il duty cicle (in percento) nella cella F42:
MODO PWM A CORR. DI FASE E FREQUENZA
Essendo questa modalità typically used for motor control, it was decided to enter the signal period Ts (rather than the frequency) and duration of the pulse width Ton (rather than the duty cycle), these two stages are inserted , respectively, in F52 cells (background color magenta) and F53 (background light blue) and must be expressed in ms:
Once defined this set of data in the table on the left appear the values \u200b\u200bof N and NO, depending on the prescaler factor k :
Per quei valori di N e NA che riportano l'indicazione "N.R." vale lo stesso discorso fatto per il modo PWM Fast.
Buon divertimento!
0 comments:
Post a Comment