Hardware manual

63
Now I will write couple of words about HalDetector. After uploading the driver with above
function and compilation of the main program we can call it by typing:
./haldetector
Next step is that we need to choose proper band rate, node to RS-232 device and the length of
phase tables. If we
checkbox. Then we just
click on the button start and wait. Detection can take up to round 5 min and should be repeated
at least two times. The reason for it is that it can by possible that when we switch the motor on,
means that when we send first PWM outputs from phase
tables, the rotor will rotate little bit in wrong direction and it will cross hall border or index
mark, giving rise to wrong results. The situation of this is presented on the picture nr 6.6-2.
Fig.6.6-2. Wrong direction of the rotor's rotation.
If it goes about the code of the program, we can say it consists from three files:
main.cpp
haldetector.h
haldetector.cpp
First from the above is just the initialization of the main window frame/widget. Second file has a
declaration of the class Form1, in which I defined all functions and variables used later in the
program. For us the most important is the private section:
private:
int fd; // device
short phaseTableLen; // length of phase tables
short *ph1,*ph2,*ph3; // phase table
bool working; // if we make some discoveries ;o)
int initport(int fd); // initialize given port