Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

the c code for 3 phase brushless DC motor control by using PIC16F877A

Status
Not open for further replies.

You Wei Lim

Newbie level 3
Newbie level 3
Joined
Jul 21, 2014
Messages
4
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Location
Melaka, Malaysia
Activity points
24
Hi guest , i have face the problem that i need to use the 3 PORT B pin as the input pin from hall sensored from bldc motor, and 6 PORT C pin as my output pin 5V to control the high side and low side of my motor driver the 3-phase BLDC motor by using a C-code programming~~below is my source code ,can compile but dint work~~ ANY SUGGESTION? URGENT!!!!!!!


Code:
   void main()
 {
  TRISA = 0xFF;
  TRISB = 0xFF;           // Set PORTB as Input
  TRISC = 0xFF;
  TRISD = 0x00;           // Set PORTD as Input
  PORTA = 0x00;
  PORTB = 0x00;
  PORTC = 0x00;
  PORTD = 0x00;
  CMCON = 0x07;
  ADCON1 = 0b10000110;
  // or
  // ADCON1 = 0b10000111;
while(1)
   {

    if(PORTB =0x14)     // If RA0 is Toggled
     {
       TRISD = 0x00;       // Set PORTB as Output
       PORTD = 0x06;       // Toggle On;

     }
       else  if (PORTB= 0x10)    //0x04 - 100
                        {
                                TRISD = 0x00  ;
                                PORTD= 0x24 ;
                                //hall_state = 5;
                        }
                        else if (PORTB= 0x18)       //0x06 - 110
                        {
                                  TRISD = 0x00 ;
                                PORTD= 0x21  ;
                                //hall_state = 6;
                        }
                        else if (PORTB= 0x08 )        //0x02 - 010
                        {
                                TRISD = 0x00 ;
                                PORTD= 0x09;
                                //hall_state = 1;
                        }
                        else if (PORTB= 0x0C)      //0x03 - 011
                        {
                                 TRISD = 0x00 ;
                                PORTD= 0x18;
                                //hall_state = 2;
                        }
                        else if (PORTB= 0x04)
                               //0x01 - 001
                        {
                                TRISD = 0x00 ;
                                PORTD = 0x12;
                                //hall_state = 3;
                        }
                        else
                        {
                                PORTD= 0x00;
                        }




    }
 }
PLS HELP!!!!!
 
Last edited by a moderator:

6 PORT C pin as my output pin

Code:
TRISC = 0xFF;

both doesn't have similarities .To configured the any port pin as output its respective TRISCx = 0.

read the datasheet before doing coding and learning the new micro controller that should be basic step for all new programmer for new controller.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top