Hello guys! 
I need help to drive a DC Motor (by a DMOS Full-Bridge Motor Driver) with PIC18F4585.
I'm trying to generate a PWM signal like EN input for Motor Driver.
I don't know where i wrong... My object is only to start the motor.
Thank you so much in advance!
I'm using MPLAB X and my code is this:
Moderators note : used code tags
I need help to drive a DC Motor (by a DMOS Full-Bridge Motor Driver) with PIC18F4585.
I'm trying to generate a PWM signal like EN input for Motor Driver.
I don't know where i wrong... My object is only to start the motor.
Thank you so much in advance!
I'm using MPLAB X and my code is this:
C:
#include <stdio.h>
#include <stdlib.h>
#include "Config_Bits.h"
#define _XTAL_FREQ 40000000 // Set the frequency of quartz used by PIC
void main(void)
{
CMCON = 7; // Disable comparators (affect dip_switch reading)
ADCON1= 0x0f; // Set PortA (5 and 3:0) as Digital Inputs
LATC = 0xff; // Cleanup output ports
LATD = 0x7f; // It sets DOUT16=RD7=0 to reach V_OPT=5V and enable outputs
TRISC = 0; // Enable output ports (C+D)
TRISD = 0;
LATD = 0xff; // ... HALT signal
PR2 = 255; /* Load period value */
CCPR1L = 80; /* load duty cycle value */
T2CON = 0; /* No pre-scalar, timer2 is off */
CCP1CON = 0x0C; /* Set PWM mode and no decimal for PWM */
TMR2 = 0; /* Clear Timer2 initially */
TMR2ON = 1; /* Timer ON for start counting*/
while(1);
Last edited by a moderator: