Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

BLDC motor speed control...

Status
Not open for further replies.
void I2C_init(), I2C_start(void), I2C_write(char x);
That gives a error Ian
I would like to see what pin the op is using to feed the SDA pin of the motor controller.
 
That gives a error Ian
I would like to see what pin the op is using to feed the SDA pin of the motor controller.

Most of the code that Ritesh post (in this thread) does not compile.. I have no idea why he fails to follow well written tutorials and even fails to copy paste code. Too lazy..
 
Last edited:
I would tell the thread opener to get the I2C thing work first. I2C isn't easy, to be honest.

Btw, there should be an address for this motor controller. Did he include this inside?
 
I would tell the thread opener to get the I2C thing work first. I2C isn't easy, to be honest.

True.. I2C is not easy to debug. From what I've seen and read, there can be so many things that is going wrong:

1) The code does not compile, but Ritesh does not notice it. Result is that he downloads an old hex file into PIC.
2) The code compiles ok, but Ritesh still uploads the same old hex file into pic over and over again. I've seen it happen few times.. even made that mistake myself.
3) Code compiles ok and updated hex is downoaled into PIC, but the code is not right.. difficult to debug even if he tries.
4) The hardware is faulty.. Impossible for us to notice without schematics or picture of the physical circuit.
 
He should try playing with the DS1307 first to mess around with the I2C. Honestly speaking, for a person who has been exposed to microcontrollers for some years, I couldn't get to write the I2C routines properly. I had written once only, but I had to refer back to the code if I have to reuse it again. Very tough!
 
Ok, i have corrected but the result is same not working....**broken link removed**

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(void),I2C_start(void),I2C_write(char x), I2cSTOP(void);	

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(void)
	{
  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);
	
	}
	
 void I2C_write(char x){
		SSPBUF=x;
		while(BF);
while((SSPCON2 & 0X1F || (SSPSTAT & 0X04)));
		
		}
			
void I2cSTOP(void ){
PEN=1;
while(PEN);
}
 

Attachments

  • s.JPG
    s.JPG
    69.3 KB · Views: 226
That gives a error Ian
I would like to see what pin the op is using to feed the SDA pin of the motor controller.


Whoops!! Correct

Code:
void I2C_init(void), I2C_start(void), I2C_write(char x);

The function parameters have to be declared void...
 
If everything is right then also not working?

Do you see any problem with that statement?

Which PIC programmer do you use? If it's a PICkit2 you have a handy three channel logic analyzer that would be pretty handy for sorting out your I2C problem. Also and I know you're not really listening post a photo of your project, as a bonus the schematic you're working from would be nice. Do you have 0.1µF decoupling caps on your ICs?
 
That's why I said Politician, you can do anything you want till the tanks come in. Then you need a helicopter and a suitcase full of money.
 
Do you see any problem with that statement?

Which PIC programmer do you use? If it's a PICkit2 you have a handy three channel logic analyzer that would be pretty handy for sorting out your I2C problem. Also and I know you're not really listening post a photo of your project, as a bonus the schematic you're working from would be nice. Do you have 0.1µF decoupling caps on your ICs?

I am using this.........
**broken link removed**
Also and I know you're not really listening post a photo of your project, as a bonus the schematic you're working from would be nice.

I have posted in previous post.
Do you have 0.1µF decoupling caps on your ICs?
I am using 22uF at 7805 output and input connected with 7.8V battery..
 
I don't recognize the programmer, looks like a 18F2550 with a voltage multiplier (something like my PICKit2 lite).
You must have 0.1µF decoupling caps near the VCC & VSS pins of every digital IC. It's not optional and is a classic noob mistake.
I've not seen them (your schematics / photos) in this thread, guess I'll have to look harder.

So add decoupling caps and make sure your I2C bus has 4.7K - 10K pullups on both SDA & SCL plus keep your wiring short. Also if you're breadboarding this be aware they're the least reliable prototyping method for high frequency and the contacts can wear out or corrode.

If you want to learn something and build a useful tool try building a PICKit2 Lite like the fellow in the link below did. Not only is it a decent 5V programmer & debugger with MPLAB support it has a terrific stand alone utility too that as a bonus has a 3 channel logic tool, a logic probe and a UART tool. Awesome for troubleshooting your designs. It can even be kludged into a Microchip compatible Serial Analyzer tool (another Microchip product).
https://okelectronic.wordpress.com/2013/02/21/diy-pickit-2-lite/

Another handy tool is the Bus Pirate. Not sure how available it is in India but I have one and it's pretty neat.

To give you a fighting chance, PM me your postal address and I'll send you a bare Junebug PCB which is an extension of my PICKit2 Lite programmer.
 
Ok, i have corrected but the result is same not working....**broken link removed**

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(void),I2C_start(void),I2C_write(char x), I2cSTOP(void);	

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(void)
	{
  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);
	
	}
	
 void I2C_write(char x){
		SSPBUF=x;
		while(BF);
while((SSPCON2 & 0X1F || (SSPSTAT & 0X04)));
		
		}
			
void I2cSTOP(void ){
PEN=1;
while(PEN);
}

Here is the fast drawn schematic.....
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top