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.
For what??

If you want me to send you a free Junebug PCB. Don't bother if you don't need it, just offering.
4177-JuneBug.png

PS your code shows, but your schematics / photos whatever don't.
 
It hangs on the while loops he made.
This
Code:
void I2C_start(void){
	SEN=1;
	while(SEN);
 
	}
Should be this
Code:
void i2c_Start(void)
{
    i2c_Wait();
    SEN=1;
}

And this
Code:
void I2cSTOP(void ){
PEN=1;
while(PEN);
}
Should be this
Code:
void i2c_Stop(void)
{
    i2c_Wait();
    PEN=1;
}
 
It hangs on the while loops he made.
This
Code:
void I2C_start(void){
	SEN=1;
	while(SEN);
 
	}
Should be this
Code:
void i2c_Start(void)
{
    i2c_Wait();
    SEN=1;
}

And this
Code:
void I2cSTOP(void ){
PEN=1;
while(PEN);
}
Should be this
Code:
void i2c_Stop(void)
{
    i2c_Wait();
    PEN=1;
}
 
The problem is, the thread opener didn't read most of the posts we made. He only cared about the answers. He will keep posting again, and again, and again, this time it's a different problem but without a solution.

It's hard to help people who refuse to help themselves. :)
 
It hangs on the while loops he made.

Where did you get the code you posted? I don't think that Ritesh even copy-pasted the i2c_Wait(); function from the source I linked.. I don't know why.. maybe he does not need it (sarcasm).
 
I looked at the library that's in xc8 and there's a link on page 8
That's doing it the same way.
I don't do any more then hold the line high as is he has
It coded it goes in the first loop and keeps the I2C line high.
 
Last edited:
Amazing.

Mike.
Yep it is there a working sample code on page 8 if the op looked
At it. There a library in XC8 which is in high tech to lol
It doesn't have all them while loops which don't add up
Your setting it to start overs and over agin
 
Is this fine now?

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), I2cSTOP(void);	
void i2c_Wait(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(100);//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)
{
    i2c_Wait();
    SEN=1;
}
	
 void I2C_write(char x){
	i2c_Wait();	
SSPBUF=x;
	

		
		}
			
void i2c_Wait(void){
    while((SSPCON2 & 0X1F || (SSPSTAT & 0X04)));
}

void I2cSTOP(void)
{
    i2c_Wait();
    PEN=1;
}
 
That would be what most people would do.

I'm starting to believe RK is a possibly a bot.


I do believe so too.

Looking at the Thread OP's webpage - he is in a senior year in EE.

I'm thinking that a senior year should have covered at least a full course in C/C++ and one or two semesters in microcontroller programming. And even if it's not, hitting and missing around is something learned in all these lab-works too.

Many years back I wasn't even studying in an EE environment. I was in Medical Technology Engineering, and I'm only halfway exposed to EE subjects. I struggled like mad in the earlier semesters, only barely passing all these subjects. On the semester breaks, I hit the books again and wildly experimented on op-amps, and some digital logic circuits, and lastly microcontrollers. Most of these are experimentation, and finally, they worked because I did it one at a time. As a person with a mild Asperger/autism, isolating problems do help a lot in understanding electronics.

Just my two cents.
 
Is this fine now?

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), I2cSTOP(void);	
void i2c_Wait(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();

	I2C_write(0x12);//esc default addr

	I2C_write(100);//testing speed 0-255

   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)
{
    i2c_Wait();
    SEN=1;
}
	
 void I2C_write(char x){
	i2c_Wait();	
SSPBUF=x;
	

		
		}
			
void i2c_Wait(void){
    while((SSPCON2 & 0X1F || (SSPSTAT & 0X04)));
}

void I2cSTOP(void)
{
    i2c_Wait();
    PEN=1;
}

Its not working man.............
 
Well there not much hope in helping you there not any way
To see what's happening and even if your told things to do you supply
No information about what's going on no sch.
And don't you have a YouTube video showing it working.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top