HWA
Bare metal programming with style
|
This class is used by:
counter0
counter0
counter0
counter0
(COUNTER,prescaler)
: class _psa prescaler;(COUNTER,compare0)
: class _oca compare unit with waveform generator;(COUNTER,compare1)
: class _oca compare unit with waveform generator.(COUNTER,irq)
, (COUNTER,irq,overflow)
: triggered when the counter counts from "max" to 0 (after_max
) in up_loop
counting mode, or when it counts from 0 to 1 (after_bottom
) in updown_loop
counting mode.
hwa( configure, ... ): configure the counting unit
overflow
is not stated, an acceptable value will be selected according to the configuration of the compare units found in the HWA context. If overflow
is stated, the validity of its value will be verified.Atmel modes:
Mode | direction | top | overflow | Overflow flag | Compare update |
---|---|---|---|---|---|
0 Normal | up_loop | max | after_max | max -> 0 | Immediate |
1 PWM, Phase correct | updown_loop | max | after_bottom | 0 -> 1 | At top |
2 CTC | up_loop | compare0 | after_max | max -> 0 | Immediate |
3 Fast PWM | up_loop | max | after_max | max -> 0 | At bottom |
5 PWM, Phase correct | updown_loop | compare0 | after_bottom | 0 -> 1 | At top |
7 Fast PWM | up_loop | max | after_top | top -> 0 | At bottom |
Example 1 - An overflow IRQ is triggered when the counter counts from 255 to 0, the frequency of the IRQs is HW_SYSHZ/8/256:
Example 2 - Counting: 0-1-2-3-2-1-0-1..., an overflow IRQ is triggered when the counter counts from 0 to 1, the frequency of the IRQs is HW_SYSHZ/64/6.
hw( read, ... ): get the count
hw( write, ... ), hwa( write, ... ): set the count
hw( clear, ... ): set the count to 0
Hardware registers:
ccra
: control register accrb
: control register bcount
, reg
: count registerocr0
: output-compare A registerocr1
: output-compare B registerimsk
: interrupt mask registerifr
: interrupt flag registerLogical registers:
wgm
: counting and waveform generation modecs
: clock selectionie
: overflow interrupt maskocie0
: compare A interrupt maskocie1
: compare B interrupt maskif
: overflow interrupt flagocif0
: compare A interrupt flagocif1
: compare B interrupt flagcom0
: output-compare mode Acom1
: output-compare mode Bfoc0
: force output-compare Afoc1
: force output-compare B