Hardware manual

61
table in an element shown by hall value the number 1 and so on, till we rotate the motor by
360
o
.
 little bit more complicated. Namely
position of the index mark is strict and its detection should be very accurate. To achieve this we
need to use little bit more advanced technology interrupt. This is mostly due to fact that
interrupts work almost immediately. We have two possibilities: we can use TPU or IRQ to detect
it. To make it more clearly in my program I decided to use IRQ
                
rotating, it crosses index mark. This generates IRQ interrupt. In the interrupt function there is
only an increment of one global variable. When we detect this increment and we know the
actual value of index for phase table, we can say where the index mark is. At this point it should
be noted that we should be very careful by detection of index mark. Namely, at the beginning of
the rotation there could be such position of the rotor, that the motor will cross index mark
giving wrong results please see the picture nr 6.6-2 and its description later in this subsection.
Before we look into the implementation of above two algorithms, we need to know what
command processor (CMD_Proc) is. About CMD_Proc we can think as a terminal program to
control the other executed program. In a normal case this terminal program has to be run by
typing its name on a terminal. On the other hand, this terminal program can be also
used/executed by some other program. For more information please look to the 7.2 subsection.
For the proper work of HalDetector we need to create one special
command processor function and one global variable inside our driver for the motor. The body
of this function is presented below:
short index_marking=0; // global variable for index mark
int cmd_do_detection(cmd_io_t *cmd_io, const struct cmd_des *des, char
*param[])
{
pxmc_state_t *mcs = &mcs_left;
short hal=0x00;
char *snd;
index_marking%=4;
// stop the motor
pxmc_clear_flag(mcs,PXMS_ENR_b);
pxmc_clear_flag(mcs,PXMS_ENO_b);
pxmc_clear_flag(mcs,PXMS_PHA_b);
pxmc_clear_flag(mcs,PXMS_PTI_b);
short ene=1024;//mcs->pxms_ene;
unsigned long pwm1=atol(param[1]);
snd=strchr(param[1],':')+1;
unsigned long pwm2=atol(snd);
snd=strchr(snd,':')+1;
unsigned long pwm3=atol(snd);