Skip to content

Asymmetric Continuous Timer

Ivan Cenov edited this page Apr 10, 2019 · 1 revision

Asymmetric Continuous Timer.

The asymmetric continuous timer (ACT) acts as a continuous timer however its period is divided into two semi-periods - one named high state (ACT_STATE_HIGH) and the other named low state (ACT_STATE_LOW). Each of these semi-periods has its own setting. At the end of each of the semi-periods a Tick flag is raised. This flag can be used by some procedure to do someting (par example manipulate outputs). As a result this timer can produce signals with different duty cycles. Blinking LEDs are most natural use case of asymmetric timers.

The ACT timers can handle the situation when one fo the semi-periods setting is zero. In such cases, the ACT timers act as Continuous timers.

Declaration.

Macro Description
DEFINE_ASYMMETRIC_CONTINUOUS_TIMER(tag,ttype) Declare an ACT timer with tag tag in .c file by decalring its variables. The type of the timer is ttype.
EXTERN_ASYMMETRIC_CONTINUOUS_TIMER(tag,ttype) Define external definitions in .h file. tag is the tag of the timer, and ttype is its type.

Variables.

Variable Description
AsymmetricContinuousTimerCounter(tag) Counter of type ttype. It can be used as lvalue. Direct access to this variable is not recommended.
AsymmetricContinuousTimerSettingHigh(tag) Setting (length) of the high state (ACT_STATE_HIGH). It can be used as lvalue.
AsymmetricContinuousTimerSettingLow(tag) Setting (length) of the low state (ACT_STATE_LOW). It can be used as lvalue.
AsymmetricContinuousTimerFlag(tag) When true this flag indicates active, working timer. It can be used as lvalue. Direct access to this variable is not recommended.
AsymmetricContinuousTimerTick(tag) This flag, when true indicates that an semi-period has expired. It can be used as lvalue.
AsymmetricContinuousTimerState(tag) This boolean variable holds current state of the timer. It can receive one of the two values ACT_STATE_HIGH and ACT_STATE_LOW. It can be used as lvalue. Direct access to this variable is not recommended.

Manipulation macros.

Macro Description
SetAsymmetricContinuousTimer(tag,perh, perl) This macro activates ACT timer with tag tag. It sets the counter to perh, AsymmetricContinuousTimerSettingHigh(tag) to perh and AsymmetricContinuousTimerSettingLow(tag) to perl. AsymmetricContinuousTimerState(tag) is set to ACT_STATE_HIGH and AsymmetricContinuousTimerTick(tag) is cleared. The macro disables the interrupts at the beginning and enables them at the end.
SetAsymmetricContinuousTimerI(tag,perh,perl) This macro activates ACT timer with tag tag. It sets the counter to perh, AsymmetricContinuousTimerSettingHigh(tag) to perh and AsymmetricContinuousTimerSettingLow(tag) to perl. AsymmetricContinuousTimerState(tag) is set to ACT_STATE_HIGH and AsymmetricContinuousTimerTick(tag) is cleared. The macro does not touch the interrupts and thus it is convenient to be used with previously disabled interrupts.
StopAsymmetricContinuousTimer(tag) This macro stops a timer with tag tag. It clears AsymmetricContinuousTimerFlag(tag) and AsymmetricContinuousTimerTick(tag). The macro disables the interrupts at the beginning and enables them at the end.
ResetAsymmetricContinuousTimer(tag) This macro stops a timer with tag tag. It clears AsymmetricContinuousTimerFlag(tag) and AsymmetricContinuousTimerTick(tag). The macro does not touch the interrupts and thus it is convenient to be used with previously disabled interrupts.
ClearAsymmetricContinuousTimer(tag) This macro clears variables of timer witgh tag tag. The macro does not touch the interrupts and thus it is convenient to be used with previously disabled interrupts.
ChangeAsymmetricContinuousTimerSetting(tag,perh,perl) This macro changes both settings for ACT_STATE_HIGH and ACT_STATE_LOW states using the arguments perh and perl.
ChangeAsymmetricContinuousTimerState(tag,perh,perl,state) This macro changes both settings for ACT_STATE_HIGH and ACT_STATE_LOW states and also changes its state using the argument state.
TickAsymmetricContinuousTimer(tag) This macro decrements the counter by one. If the counter becomes zero then the state of the timer changes to the opposite one and a new semi-period is loaded into the counter, corresponding to the new state. However, if the oppsite state has zero setting, then the state of the timer is not changed. In all cases, this macro raises AsymmetricContinuousTimerTick(tag).
ClearAsymmetricContinuousTimerTick(tag) This macro clears AsymmetricContinuousTimerTick(tag).

Clone this wiki locally