Hardware manual

56
const unsigned char
eurobot_bdc_hal_pos_table[8]=
{
[0]=0xff,
[5]=0, //1 0 1 = 5
[1]=1, //0 0 1 = 1
[3]=2, //0 1 1 = 3
[2]=3, //0 1 0 = 2
[6]=4, //1 1 0 = 6
[4]=5, //1 0 0 = 4
[7]=0xff,
};
Another mentioned structure was pxms_state. In this case I gave it the name mcs_left and
theoretically it should represent the left motor. As the default I assumed that the position of the
motor should be automatically updated flag PXMS_ENI_m. Functions for input, output,
controller and hardware update are standard one. The maximal difference between the actual
and requested position was set up to the half of IRC value during one rotation. Maximal speed
was chosen arbitrary to 100, and maximal acceleration to 1. The addresses for input and output
information were chosen according to selected TPU and PWM registers. P, I and D constants
were selected after small tuning and should be enough for normal work of the motor. Maximum
energy is calculated by formula represented by following equation:
CPU_SYS_HZ/PXMC_HZ
Where: CPU_SYS_HZ is CPU frequency (it is defined in system system_def.h file). PXMC_HZ
represents the sampling frequency in which PXMC should work and it is given in Hz. Values of
pxms_ptirc, pxms_ptper depends on chosen phase table. In this case it was 2048 and 1
respectively. The last important things about this configuration are configuration flags. Here I
decided that the motor should generate error always whenever the absolute difference
between actual and requested position will be greater then pxms_md. Additionally, the
controller uses limited switch, we should have the possibility to chose polarity of the switch, the
initial rotation should be clockwise and all transitions should be smooth.
pxmc_state_t mcs_left={
pxms_flg:PXMS_ENI_m,
pxms_do_inp:motor_do_input,
pxms_do_out:motor_do_output,
pxms_do_con:pxmc_pid_con,
pxms_do_ap2hw: tpu_irc_ap2hw,
pxms_md:131074<<8, pxms_ms:100, pxms_ma:1,
pxms_inp_info:(long)TPU_TCNT1, /*chanel TPU A,B*/
pxms_out_info:(long)PWM_PWBFR1A, /*chanel PWM A,B*/
pxms_ene:0,
pxms_p: 100, pxms_i: 20, pxms_d: 100, pxms_s1: 0, pxms_s2:
0,