DC motor control with PIC16F877A and rotary encoder CCS C code. PORTB interrupt on change (IOC) is used to detect the movement of the rotary encoder. CLK and DT pins are connected to RB4 and RB5 respectively. The rotary encoder push button terminal is connected to pin RB3, with this button we can change the direction of rotation of the motor. The active PWM pin decides the motor direction of rotation (one at a time, the other output is logic 0). By setting both modules in PWM mode we get 2 PWM signals with the same frequency on pins RC2 (PWM1) and RC1 (PWM2), at any time there is only 1 active PWM, this allows us to control the direction as well as the speed by varying the duty cycle of the active PWM signal. The PIC16F877A microcontroller has two CCP modules, CCP1 and CCP2 (CCP: Capture/Compare/PWM). Pin IN1 and pin IN2 are the control pins where: IN1 The L293D is supplied with 2 different sources, the first one (VCC1) is +5V, and the 2nd one (VCC2) is +12V which is the same as motor nominal voltage. The rotary encoder generates (when rotating) two square waves on pins A (CLK) and B (DT) with 90° out of phase as shown in the figure below:Īs shown in the figure, the rotary encoder has 4 phases: With the three pull-up resistors, the normal state of each terminal is logic high. The rotary encoder has 5 pins: GND, + (+5V or 3.3V), SW (push button), DT (pin B) and CLK (pin A).Īs an addition to the rotary encoder there is a push button and three pull up resistors for pins SW, DT and CLK of 10K ohm. In this example I used the rotary encoder shown in the image below: Previously I posted an example shows how to control a DC motor speed and direction using PIC16F877A and a potentiometer, example link is below:ĭC motor control with PIC16F877A and L293D – Proteus simulation Serial.This example shows how to use a rotary encoder with PIC16F877A microcontroller in order to control the speed and direction of rotation of a DC motor. Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS) It generates an analog or digital signal depending on the rotational movement. * initialize an instance of class NewKeypad */ It determines the amount and the type of rotation. If (code(&results)) / connect to the column pinouts of the keypad */ Receiver.blink13(true) // enable blinking of the built-in LED when an IR signal is received } Receiver.enableIRIn() // enable the receiver Serial.begin(9600) // begin serial communication with a baud rate of 9600 Unsigned long key_value = 0 // variable to store the key value IRrecv receiver(RECEIVER_PIN) // create a receiver object of the IRrecv classĭecode_results results // create a results object of the decode_results class #define RECEIVER_PIN 2 // define the IR receiver pin of the ping to the reception of its echo off of an object. duration is the time (in microseconds) from the sending Read the signal from the sensor: a HIGH pulse whose Give a short LOW pulse beforehand to ensure a clean HIGH pulse: The sensor is triggered by a HIGH pulse of 10 or more microseconds.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |