Cantafford
Member
Hello,
I'm trying to control a BLDC motor with PIC18f2431 and control it's speed
. I'm trying to use the PCPWM module's override function to control each transistor of my inverter bridge and send PWM signals to it in order to control the motor speed. This is the schematic:
I set transistors to be in independent mode(0&1, 2&3, 4&5) and I calculated the frequency(period) to be 1.5Khz. For starters I want to control the motor with 75% duty cycle to see if it works and then I will modify the speed using a POT. So for now I calculated the PWM duty cycle to be 75% for all transistors(by updating each PDCxL and PDCxH) and tried to turn them on individually using the OVDCONS registers.
This is the code:
The transistors do not change state at all upon running the simulation in proteus. They are just stuck in a certain state.
I'm trying to control a BLDC motor with PIC18f2431 and control it's speed

I set transistors to be in independent mode(0&1, 2&3, 4&5) and I calculated the frequency(period) to be 1.5Khz. For starters I want to control the motor with 75% duty cycle to see if it works and then I will modify the speed using a POT. So for now I calculated the PWM duty cycle to be 75% for all transistors(by updating each PDCxL and PDCxH) and tried to turn them on individually using the OVDCONS registers.
This is the code:
Code:
#include <stdio.h>
#include <stdlib.h>
#include "header.h"
int HALL;
int HALLvalue[6] = { 0b00000101, 0b00000001, 0b00000011, 0b00000010, 0b00000110, 0b00000100 };
// Capture Interrupt Service Routine
void interrupt CheckHallValue()
{
IC1IF = 0; IC2QEIF = 0; IC3DRIF = 0;
HALL = (PORTA >> 2) & 0x7; // read the capture pins to get hall sensor state
if(HALL == HALLvalue[0]) {OVDCONS = 0b00100100; PDC2H = 0x03; PDC2L = 0x12; PDC1H = 0x03; PDC1L = 0x12;} // and give
else if(HALL == HALLvalue[1]) {OVDCONS = 0b00000110; PDC1H = 0x03; PDC1L = 0x12; PDC0H = 0x03; PDC0L = 0x12;} // appropiate phase sequence (duty cycle is supposed to be 75%)
else if(HALL == HALLvalue[2]) {OVDCONS = 0b00010010; PDC2H = 0x03; PDC2L = 0x12; PDC0H = 0x03; PDC0L = 0x12;} //
else if(HALL == HALLvalue[3]) {OVDCONS = 0b00011000; PDC2H = 0x03; PDC2L = 0x12; PDC1H = 0x03; PDC1L = 0x12;} //
else if(HALL == HALLvalue[4]) {OVDCONS = 0b00001001; PDC1H = 0x03; PDC1L = 0x12; PDC0H = 0x03; PDC0L = 0x12;} //
else if(HALL == HALLvalue[5]) {OVDCONS = 0b00100001; PDC2H = 0x03; PDC2L = 0x12; PDC0H = 0x03; PDC0L = 0x12;} //
}
void main()
{
OSCCON = 0b01001111; // frequency is 1Mhz
ANSEL0 = 0b00000000; // set portA to digital
TRISA = 0b11111111; // PORTA is input(CAP's + POT)
TRISB = 0b11000000;
GIE = 1; // enable global interrupts
GIEH = 1; // enable high interrupts
PEIE = 1; // enable pheripheral interrupts
// Initialize the Input Capture Module
CAP1CON = 0b00000000; // disable input capture 1 module
CAP1CON = 0b00001000; // enable input capture 1 module; interrupt on every state change
CAP2CON = 0b00000000; // disable input capture 2 module
CAP2CON = 0b00001000; // enable input capture 2 module; interrupt on every state change
CAP3CON = 0b00000000; // disable input capture 3 module
CAP3CON = 0b00001000; // enable input capture 3 module; interrupt on every state change
// Enable Capture Interrupt and configure TMR5
IC1IE = 1; // enable IC1 interrupt
IC1IP = 1; // IC1 interrupt on high priority
IC1IF = 0; // clear IC1 interrupt status flag
IC2QEIE = 1; // enable IC2 interrupt
IC2QEIP = 1; // IC2 interrupt on high priority
IC2QEIF = 0; // clear IC2 interrupt status flag
IC3DRIE = 1; // enable IC3 interrupt
IC3DRIP = 1; // IC3 interrupt on high priority
IC3DRIF = 0; // clear IC3 interrupt status flag
//Configure PCPWM module
PTCON0 = 0b00000000; // 1:1 postscale, input timebase FOSC/4(1:1 prescale), PWM in free-running mode
PTCON1 = 0b11000000; // ??? PWM Time base on, pwm time base counts down
PWMCON0 = 0b01001111; // PWM 0-5 activated in independent mode
//PWMCON1
//DTCON
OVDCOND = 0b00000000; // Output PWM controlled by corresponding POUT bit(active when set)
PTPERH = 0x10; // TPWM CALCULATION (PTPER supposed to be 0xA4)
PTPERL = 0x04; // frequency is 1.5Khz(PTMRPS=1)
// Configure TMR5 module
T5CON = 0b00000101;
PDC2H = 0x03; PDC2L = 0x12; PDC1H = 0x03; PDC1L = 0x12; // kickstart
OVDCONS = 0b00100100; // the motor
while(1)
{
}
}
The transistors do not change state at all upon running the simulation in proteus. They are just stuck in a certain state.