HWA
Bare metal programming with style
Class _ctd: 16-bit counter with two compare units and one capture unit

This class is used by:

Relatives

Interrupts

Actions



hwa( configure, ... ): configure the counting unit

hwa( configure, counter0,
// How the counter is clocked
//
clock, none // No clock, the counter is stopped
| ioclk [/ 8|64|256|1024] // IOCLK divided by 1,8,64...
| external_rising // External input, rising edge
| external_falling, // External input, falling edge
// How does this counter count
//
direction, up_loop // Count from bottom to top and loop
| updown_loop, // Count up and down alternately
[ bottom, 0, ] // Default, no other choice
// The maximum value the counter reaches
//
[ top, 0xFF | 0x00FF | 255 // Hardware fixed value 0x00FF
| 0x1FF | 0x01FF | 511 // Hardware fixed value 0x01FF
| 0x3FF | 0x03FF | 1023 // Hardware fixed value 0x03FF
| 0xFFFF | 65535 | max // Hardware fixed value 0xFFFF (default)
| compare0 // Value stored in the compare0
| capture0, ] // Value stored in the capture0
// When the overflow flag is set
//
[ overflow, after_bottom // When the counter resets to bottom
| after_top // When the counter reaches the top value
| after_max ] // When the counter reaches its max value
);
Note
If a compare unit is used, its configuration must be done inside the same context as the counter so that HWA has all the necessary informations to choose the correct register settings.
If the optionnal argument 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.



hw( read, ... ): get the count

uint8_t n = hw( read, counter0 );



hw( write, ... ), hwa( write, ... ): set the count

hw( write, counter0, value );
hwa( write, counter0, value );

Registers

Hardware registers:

Logical registers:

hwa
#define hwa(...)
hwa( action, object [,...] ) stores an action for an object into a HWA context.
Definition: hwa_macros.h:552
hw
#define hw(...)
hw( action, object [,...] ) executes an action immediately on an object.
Definition: hwa_macros.h:523