Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


Share this Page URL
Help

PICDEM DC Motor Test Programs > Basic Control - Pg. 126

C Mechatronics Applications }/////////////////////////////////////////////////////////END 4.3. PICDEM DC Motor Test Programs · Motor test program · Rev counter program The primary target device on the board is the DC motor. The hardware configuration is shown in Figure 4.8. The first program just switches the motor on and off, and the second shows how to control the speed. Figure 4.8. Block Diagram of Motor Test System Basic Control The minimal program (Listing 4.5) shows how to run the mechatronics board under the control of SW2. The motor is connected to Drive1 and Drive2 output terminals, with two output bits of the MCU linked to P1 and N2. When these go high, the motor current is switched on in a forward direction. The output code 0×90=10010000 2 switches on RD4 and RD7 when the switch input RA4 goes low. If desired, the PIC output pins can also be monitored on the LEDs. The project should be loaded and tested as described in Section 4.1. Listing 4.5. Motor Test Program //MOTOR1.C MPB 17-4-07 PICDEM board test program //Control motor from switch. Connect SW2-RA4, RD7-P1, RD4-N2 #include"16F917.h" void main() { while(1) { if(!input(PIN_A4)) //Test switch output_D(0x90); //Switch on motor else output_D(0x00); //Switch off motor 126