DC Motor For 75% PDF

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

//Includes

#include <p18f4550.h>

#pragma config FOSC = HS

#pragma config WDT = OFF

#pragma config LVP = OFF

#pragma config PBADEN = OFF

void myMsDelay (unsigned int time)

unsigned int i, j;

for (i = 0; i < time; i++)

for (j = 0; j < 710; j++); // Calibrated for a 1 ms delay in MPLAB

void main()

TRISCbits.TRISC2 = 0 ; // Set PORTC, RC2 as output (CCP1)

TRISCbits.TRISC6 = 0 ; // Set PORTC, RC6 as output (DCM IN3)

TRISCbits.TRISC7 = 0 ; // Set PORTC, RC6 as output (DCM IN4)

PR2 = 0xBA; // set PWM Frequency 4KHz

CCP1CON = 0x0C; // Configure CCP1CON as PWM mode.

T2CON = 0x07; //Start timer 2 with prescaler 1:16

PORTCbits.RC6 = 1; // Turn ON the Motor

PORTCbits.RC7 = 0;

while(1) // Endless Loop

// ----------Duty Cycle 75%-----------

CCP1CONbits.DC1B0 = 0;

CCP1CONbits.DC1B1 = 1;
CCPR1L = 0x38;

myMsDelay(2000);

// -----------------------------------

You might also like