class::hal::Tmr

class hal::Tmr
  : public hal::Periph< tmr_info_t, tmr_attr_t, TmrAttributes, TMR_IOC_IDENT_CHAR >

This class implements a hardware timer. The Timer class implements a logical timer that is based on the system clock and can be used for many timing functions.

The Tmr class can be used to configure a timer to count rising edges on an input capture pin or to generate waveforms on an output compare pin. It can also configure the timer to use the internal CPU clock at various frequencies.

For example this will start a microsecond timer (1Mhz) using an internal clock:

Tmr tmr(0); //use /dev/tmr0
tmr.init(); //initialize the timer
tmr.set(0); //set the value to zero
tmr.on(); //turn the timer on
Timer::wait_milliseconds(100);
printf("My timer value is %d\n", tmr.value()); //The value will be about 100,000

Here is an example using the Tmr to count external edges on input capture 0


You can also use the output compare channels to set the top value of the timer.


Summary

Tmr(

port_t port
)

int disable() const

int enable() const

u32 get_channel(

u32 loc
)

u32 get_value() const

int init(

u32 o_flags,
u32 freq,
u32 period,
const tmr_pin_assignment_t * pin_assignment
)

int set_attr(

u32 o_flags,
u32 freq,
u32 period,
const tmr_pin_assignment_t * pin_assignment
)

int set_channel(

u32 loc,
u32 value
)

int set_value(

u32 value
) const

enum tmr_flags

Members

Tmr(

port_t port
)

Constructs a new timer object using port.


int disable() const

Turns the TMR off (stop counting)


int enable() const

Turns the TMR on (start counting)


u32 get_channel(

u32 loc
)

Gets the value of the specified channel.

Parameters

  • loc The channel number

Returns

The value of the channel or (u32)-1 if the IOCTL request fails

The loc parameter is the input or output channel. Input channels should be or’d with the MCU_CHANNEL_FLAG_IS_INPUT value.


u32 get_value() const

Gets the value of the timer.


int init(

u32 o_flags,
u32 freq,
u32 period,
const tmr_pin_assignment_t * pin_assignment
)


int set_attr(

u32 o_flags,
u32 freq,
u32 period,
const tmr_pin_assignment_t * pin_assignment
)


int set_channel(

u32 loc,
u32 value
)

Sets the value of the specified channel.

Parameters

  • loc The channel number

  • value The value to assign to the channel

Returns

Zero on success

The loc parameter is the input or output channel. Input channels should be or’d with the MCU_CHANNEL_FLAG_IS_INPUT value.


int set_value(

u32 value
) const

Sets the value of the timer.


enum tmr_flags

X

Thanks for Coming!

Subscribe to news and updates