BLDC motor speed control...

Status
Not open for further replies.
Yes. What I can't understand is:

1) The example code configured the ports as input
2) I said: "configure the ports as inputs.. follow the example code
3) Ritesh configured the ports as output

I have changed it but now also it is not working.
 
Motor wired wrong or something

LED Info
LED 1 – on when powered up and motor is in stand-by. Off when motor is running.
LED2 – blinks if there is a hardware error on start-up. Blinks 10 times if there is a short-circuit detected or abnormally high current through the circuit.
 
So what is LED2 doing? On permanently, or blinking once or 10 times?
 
From what I take you could use pwm to set speed using same
Pins
 
Wonder what that means lol. Read the end of the manual it tells you that on power it will test the motor then if you don't turn it on both leds will end up on. To turn it on you can do what looks like 3 ways the easy way would be as i posted. Maybe thats to easy.

I would go with number 8 and PWM the SDA pin .
 
Last edited:
But what is the problem with I2C..?

Have you ever used a simple LED to debug your code? Connect a LED to a free IO pin and try to find out at what point the code stops. I bet it is one of the I2C functions that makes the code halt.. find out which one.
 
But what is the problem with I2C..?
Forget I2C for now. Do as be80be suggested and first make sure the hardware is functioning properly. If it is, then you know the code is the problem.
 
I have connected PWM it was working but not so good, after maximum speed it does decrease with PWM and i don't like it ..
anyway i have tested the I2c it is networking i have added led in between for testing but no result found.


Code:
#include <htc.h>
__CONFIG(LVP_OFF & BOREN_OFF & PWRTE_ON & WDTE_OFF & FOSC_HS);
#define _XTAL_FREQ 20000000

#define SDATA RC4
#define SCLK RC3
void I2C_init(),I2C_start(void);I2C_write(char x);
void I2cSTOP();	

void main(void){
	
	TRISC3=1; //direction to input have be changed
	TRISC4=1;
TRISC0=0;
TRISC1=0;
TRISC2=0;
RC0=0;
RC1=0;
RC2=0;
__delay_ms(500);
    I2C_init();
__delay_ms(50);
	I2C_start();
RC0=1;
	I2C_write(0x12);//esc default addr
RC1=1;
	I2C_write(200);//testing speed 0-255
RC2=1;
   I2cSTOP();
while(1){

RC0=0;
RC1=0;
RC2=0;
__delay_ms(500);
RC0=1;
RC1=1;
RC2=1;
__delay_ms(500);
}
}




void I2C_init()
	{
  SSPCON = 0x38;      // set I2C master mode
 SSPCON2 = 0x00;
SSPADD = 0x0C;  //400KHZ  20MHz xtal
SSPSTAT|=0X80;
 PSPIF=0;      // clear SSPIF interrupt flag
 BCLIF=0;      // clear bus collision flag
}

void I2C_start(void){
	SEN=1;
	while(SEN);
	
	}
	
 I2C_write(char x){
		SSPBUF=x;
		while(BF);
while((SSPCON2 & 0X1F || (SSPSTAT & 0X04)));
		
		}
			
void I2cSTOP( ){
PEN=1;
while(PEN);
}
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…