Partial Code and instructions found in attachment. lecture_12_lab_4.pdfProject Objective

In this project, A DC motor need to run according to the following time
schedule:
1.
2.
3.
4.
5.
6.
7.
The motor runs in the forward direction for 4 seconds @ 70% duty cycle
The motor stops for 1 second
The motor runs in the reverse direction for 3 seconds @ 50% duty cycle
Motor stops for 2 second.
The motor runs in the forwards direction for 3 seconds @ 40% duty cycle
Motor stops for 1 second
The motor runs in the forward direction for 5 seconds @ 20% duty cycle
DC Motor
• When the DC current is
perpendicular to the
magnetic field, an
electromagnetic force
(Lorenz Force) is exerted on
the armature (coil) making
it rotating.
• The total power delivered
to the motor is
– = = +
PWM to Control DC Motor
• The coil of the motor is a large inductor where its voltage is
defined by:

– =
– If > 0 the current is increasing, if < 0 the current is decreasing • The current can be controlled using PWM technique – Apply rectangular pulse with varying duty cycle – = + − H-Bridge • H-Bridge is used with PWM to control DC Motor – The voltage across the motor is inverted according to the duty cycle • PMOD HB5 is H-Bridge module that is provided by DIGILENT – It takes the direction and the digital pwm pulse that controls the motor. – It also provides two current sensors Software Development • Configure the system clock at 80MHz, and the peripheral clock at 10MHz. • User Timer 1 for pulsing the PWM with a giving duty cycle. • Use Timer 2 for measuring the motor run time • Define three functions – Forward(RunTime, Duty_Cycle); – Stop(RunTime); – Backward(RunTime, Duty_Cycle); Clocks Configuration IOs & Timers Configurations Wait on Btn1 Run Motor Forward Stop Motor Run Motor Backward ⁞ End Initializaing The System Clock 8MHz ÷2 FPLLIDIV=2 4MHz × 20 80 MHz FPLLMUL=20 #include //Configure the clock #pragma config FNOSC = PRI #pragma config FPLLIDIV = DIV_2 #pragma config FPLLMUL = MUL_20 #pragma config FPLLODIV = DIV_1 #pragma config FPBDIV = DIV_8 void main(){ // enter your code } ÷1 80MHz FPLLODIV=1 // Oscillator Selection Bits (Primary Osc (XT,HS,EC)) // PLL Input Divider (2x Divider) // PLL Multiplier (20x Multiplier) // System PLL Output Clock Divider (PLL Divide by 1) // Peripheral Clock Divisor (Pb_Clk is Sys_Clk/8) Main void main(){ // Setting up PIC modules such as Timers, IOs OCs,Interrupts, ... InitializeIO(); InitializeLEDs(); InitializeTimers(); while(1) // endless loop { WaitOnBtn1(); Forward(4.0,70); Stop(1.0); Backward(3.0,50); Stop(2); Forward(3.0,40); Stop(1.0); Backward(2.0,20); LEDsOFF(); } return; } Initialize IOs & Timers void InitializeIO(){ TRISAbits.TRISA6 = 1; TRISAbits.TRISA7 = 1; TRISGbits.TRISG12 = 0; TRISGbits.TRISB13 = 0; LATGbits.LATB12 = 0; LATGbits.LATB13 = 0; return; } void InitializeTimers(){ // Initialize Timer1 T1CON = 0x0000; // Set Timer1 Control to zeros T1CONbits.TCKPS=3; // prescale by 256 T1CONbits.ON = 1; // Turn on Timer PR1= 0xFFFF; // Period of Timer1 to be full TMR1 = 0; // Initialize Timer1 to zero // Initialize Timer2 T2CON = 0; T2CONbits.TCKPS = 7; // prescale by 256 T2CONbits.T32 = 1; // use 32 bits timer T2CONbits.ON = 1; PR2 = 0xFFFFFFFF; // Period is set for 32 bits TMR2 = 0; } WaitOnBtn1() & Forward() void WaitOnBtn1(){ // wait on Btn1 indefinitely while(PORTAbits.RA6 == 0) ; // Turn On LED1 indicating it is Btn1 is Pushed LATBbits.LATB10 = 1; return; } void Forward(float Sec, int D){ int RunTime = (int)(Sec*39000); // convert the total time to number of Tics TMR2 = 0; //LEDs LATGbits.LATG12 = 1; // forward Direction LATBbits.LATB12 = 0; LATBbits.LATB13 = 0; LATBbits.LATB11 = 1; // Keep on firing the PWM as long as Run time is not elapsed while (TMR2 < RunTime){ PWM(D); } return; } WaitOnBtn1() & Forward() void PWM(int D){ TMR1 = 0; int Period = 400; while (TMR1< Period) { if (TMR1 < Period*D/100){ LATGbits.LATG13 = 1; } else{ LATGbits.LATG13 = 0; } } Purchase answer to see full attachment




Why Choose Us

  • 100% non-plagiarized Papers
  • 24/7 /365 Service Available
  • Affordable Prices
  • Any Paper, Urgency, and Subject
  • Will complete your papers in 6 hours
  • On-time Delivery
  • Money-back and Privacy guarantees
  • Unlimited Amendments upon request
  • Satisfaction guarantee

How it Works

  • Click on the “Place Order” tab at the top menu or “Order Now” icon at the bottom and a new page will appear with an order form to be filled.
  • Fill in your paper’s requirements in the "PAPER DETAILS" section.
  • Fill in your paper’s academic level, deadline, and the required number of pages from the drop-down menus.
  • Click “CREATE ACCOUNT & SIGN IN” to enter your registration details and get an account with us for record-keeping and then, click on “PROCEED TO CHECKOUT” at the bottom of the page.
  • From there, the payment sections will show, follow the guided payment process and your order will be available for our writing team to work on it.