Hardware manual

38
If we want to check whether some flag is set or not, we need to check
pxms_flg. This is a bit field where the flags are stored in pxmc structure. Of course, in this
fact, that one flag uses only one bit and if we want to spare memory, we can keep all of
them only in one byte or integer. Using this approach we need some way to
detect/establish which positions are occupied by different flags. Solution looks like this:
PXMS_ENI_b uses 1
st
bit, PXMS_ENR_b uses 2
nd
bit and so one. Now if we want to check if
PXMS_ENR_b is switch on, we need to shift it once to the left and then compare the state
of this bit with desired one. To avoid all shift operations and to make the program and
library more clear, in pxmc.h we have already defined all desired shifts correlated with
proper flag. They are also In other words,
It is also good to note, that using this approach, we can enable or disable flag, without a
need to call pxmc_clear_flag or pxmc_set_flag. We can do it directly. For example, to
enable PXMS_ENI_b we can do this:
mcs->pxms_flg|= PXMS_ENI_m
And if we want to disable PXMS_ENI_b we do this:
mcs->pxms_flg&= ~PXMS_ENI_m
Finally to check if some flag is enabled we can do this:
(mcs->pxms_flg&PXMS_ENI_m)
The mcs in above examples is abbreviation of motor control structure and is a pointer to
pxmc_state structure, which describes our motor. We will keep the name of this pointer
in this way also in later sections of this document.
After describing flags, it's the highest time to go into details about pxmc_state structure.
Before we do it, we need to be familiar with couple of things. Firstly, as we will see some
of the values are shifted by PXMC_SUBDIV. This can be represented by the following
formula:
Where IRC is some value given in IRC units explanation of IRC units is given in following
lines.