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.
Why input not output?

I think it doesn't even matter how you configure the pins because the I2C hardware handles the pins according to I2C specs anyway.

Edit: Why configure them as input and not output, if it does not matter? Well, input is safer (electrically) than output.
 
Last edited:
I have used them as output and it is not working code is as per your post.

Do you have pull-up resistors installed to SDA and SCL?

Post the code.
 
Post the code. And a picture of the whole system.
 
Have you tested that the controller works?

From the manual:
The brushless motor and driver can be tested by connecting GND to the SCL pin and applying a fixed analog voltage from 0V to 5V on the SDA pin using a 1kohm – 100kohm potentiometer. The driver will enter test mode on start-up if SCL is connected to GND and start the motor at a speed depending on the voltage on the SDA pin. This can be used to simply test the functionality of the motor driver and the brushless motor.
 
Pulse Proportion Modulation seems to be nothing more than a word game by the makers of Arduino.

It is the pulse width of the signal that controls the servo's position. It is not the proportion of that signal to the 20 mS refresh rate that controls position. Albeit, if you mess with the refresh rate (i.e., the proportion of on time), you can change the position slightly. Nevertheless, that is not the means used for control.

Every servo manufacturer calls it pulse width, and that is the term I used. Even the illustration in the Arduino paper shows pulse width, not the proportion of that width to the total period.

Of course, there can be confusion between terms that are often used in referring to PWM control of DC motors, such as duty cycle, which do not apply to the PWM used for servo control. Ironically, if we want to play word games, I think that "PWM" used for motor control may arguably be called Pulse Proportion Modulation more accurately.

I am worried about getting too off topic here and would to stick to the matter of helping Ritesh find a simple way to control that ESC with his microcontroller. I think that producing the appropriate PWM signal will probably lead to success faster than trying to work through the I2C protocol. At least there are lots of examples to work from.

John

Here's a link to a worked example using the 16F877A: https://www.electro-tech-online.com/custompdfs/2013/06/servo_controller.pdf
 
Last edited:
Here is the code.......

You are not waiting for the transfer to complete.
try:

C:
 I2C_write(char x){
		SSPBUF=x;
		while(BF);

    /* wait for any pending transfer */
while ( ( SSPCON2 & 0x1F ) || ( SSPSTAT & 0x04 ) );

		
		}

Also remove the delays from the transfer sequence. Only put them around the init.

C:
void main(void){
	
TRISC3=0;
TRISC4=0;
__delay_ms(200);
I2C_init();
__delay_ms(50);

I2C_start();
I2C_write(0x12);
I2C_write(100);
I2C_STOP();
	while(1){
	}
}
 
Also from the Init function, change this:

SSPSTAT=0X80;

to this:

SSPSTAT |= 0X80;
 
I have tested the esc it is working as per manual but with uC it is not i2c seems to be wrong.
The ckt scl and sda is connected with 5k pull up and the esc 5v and 8v power supply.
 
I have tested the esc it is working as per manual but with uC it is not i2c seems to be wrong.
The ckt scl and sda is connected with 5k pull up and the esc 5v and 8v power supply.

If you have working PWM code, or if you want to write one, try to feed PWM signal to the PPM pin. I'm pretty sure it works!
 
But what is the problem with i2c?

Very difficult to say. Even when you are given full code examples, you fail to copy them.

And where to feed pwm scl or sda?
There is no ppm pin.

The ppm pin is the ball of solder near the processor. I think there is a text "ppm" near it. You need to solder a wire directly to it.
 
I think it doesn't even matter how you configure the pins because the I2C hardware handles the pins according to I2C specs anyway.

Edit: Why configure them as input and not output, if it does not matter? Well, input is safer (electrically) than output.

I've fallen into this misconception as well setting ports as output and wondering why the peripherals associated with that port aren't working.

If I remember rightly, setting the port as input allows the peripheral to have control (input and output) over that port. Setting it as an output often stops the peripheral working on that port.

If the datasheet says to do so, do it.
 
So what to do?

Either pay attention to the advice and examples given or choose a different career path.

PS if you're trying to get a grip on serial communications like I2C an oscilloscope or better yet logic analyzer is a worthwhile investment. On the cheap and very useful the Bus Pirate is pretty handy, I just bought one.
 
I've fallen into this misconception as well setting ports as output and wondering why the peripherals associated with that port aren't working.
If I remember rightly, setting the port as input allows the peripheral to have control (input and output) over that port. Setting it as an output often stops the peripheral working on that port.
If the datasheet says to do so, do it.

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
 
Last edited:
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

It makes for another 10 pages of discussion doesn't it ;)
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top