Label definition
;**************** Label Definition ********************
cblock h'0c'
The data area is automatically assigned from 0ch by CBLOCK directive. ENDC is used for the ending of assignment.
The purpose of each data area is shown below.
Label |
| Purpose |
mode | : |
This is the area which manages the condition of the motor control.
0=Stop, 1=Clockwise, 2=Counterclockwise |
count1 | : |
This is the count area to make control waiting time.
It counts 1 millisecond five times and 5 milliseconds are made. |
count2 | : | This is the counter to make 1 millisecond. |
Program start
;**************** Program Start ***********************
Instruction is executed from Zero addresses of the program memory when making the power ON of the PIC. When there is interruption processing, processing is begun from the addresse 4. Because it isn't using interruption this time, there is not program execution from the addresse 4. It makes the interruption prohibition condition if the interruption occurs. It isn't necessary to do this processing.
Initialization process
;**************** Initial Process *********************
The following processing is done as the processing of being initialized after the turning on.
The initialization of the mode of port A |
![](gif/blank_20x1.gif) | All ports are set to output mode. |
![](gif/blank_1.gif) |
The initialization of the mode of port B |
| RB0,1,2 and 5 are set to input mode. And RB7 is set to output mode. |
![](gif/blank_1.gif) |
Port B pull-ups are disabled (RPBU=1) |
| Because RB5 is used as the high impedance input at the circuit this time, the RB pull up feature should not be used. |
![](gif/blank_1.gif) |
Setting of a stop mode |
| Immediately after turned on, it sets a motor to the stop mode. When there is not this step, the original value of mode becomes 0. It is put for the safety. |
![](gif/blank_1.gif) |
Counters for the control waiting time are initialized |
| There is not a problem even if there is not these processing. They are put for the safety. |
![](gif/blank_1.gif) |
Port A initialization |
| It sets 0101 as the initial state of port A. Because it drives with the transistor, the logic reverses. It is in the condition, =H =L =H =L, from the bit on the left. |
![](gif/blank_1.gif) |
Discharging of the capacitor for the speed control |
| It makes RB7 H level and it makes TR1 ON and discharging in the electric charge of the capacitor for the speed control. The end of the discharge is confirmed by RB5. |
Switch condition confirmation process
;************* Check switch condition *****************
It detects the ON condition of the stop switch, the RRC switch, the RLC switch. A condition is set to mode according to the kind of the switch which was made ON. The order of the detection is a stop, a RRC, a RLC. When more than one switch is pushed at the same time, the switch which detected ON earlier is effective.
This processing is done every time it controls 1 step of motor.
Motor drive process
;******************** Motor drive *********************
A stop mode is checked first. In case of the stop mode, it doesn't drive the motor and it jumps to the switch condition confirmation process.
In case of not being a stop mode, the following process is done.
Discharging of the capacitor for the speed control |
![](gif/blank_20x1.gif) | Discharging the capacitor as the preparation to make the timing of the speed control. |
![](gif/blank_1.gif) |
The wait processing of 5 milliseconds |
|
In the high-speed control, the rotor doesn't follow the change of the magnetic pole and the step motor doesn't rotate normally. It sets a timer value to turn a full speed normally.
In case of the motor which was used this time, it doesn't rotate normally when making less than 5 milliseconds. |
![](gif/blank_1.gif) |
The charging of a capacitor for the speed control and the confirmation process |
| It makes RB7 an L level and it begins charging the capacitor. It confirms that the charging completes by RB5. It is completion if RB5 becomes H level. Correctly, it is not charging completion and it is the fact that the voltage of the capacitor became above the threshold voltage of RB5. |
![](gif/blank_1.gif) |
The motor drive process |
|
After the speed control timing, a motor is driven. The control state of the motor is confirmed first. This is done by reading the condition of port A. Next, whether it is a clockwise mode or a counterclockwise mode is judged. The following control state which should drive a motor by the result is set to port A. Because there are four conditions, processing is done in each condition.
After the motor drive process, it jumps again to the switch condition confirmation process. |
|