Controlling a brushless with dsPic

Thread Starter

alexix

Joined Mar 27, 2014
5
I have a dsPIC30F4012, a brushless motor and this ESC

After reading the web, I understood that ESC require servo pulse (1-2ms up then 18-19 ms down) so I made this code:

Rich (BB code):
int16_t main(void){
TRISB = 0x00;
PORTB = 0x00;

int i=0;
for(i=0;i<300;i++){
PORTB=0x01;
__delay32(30000);   // 1 ms?
PORTB=0x02;
__delay32(600000-30000);    // 19 ms?
}
while(1){
        PORTB = 0x01;
	__delay32(60000);   // 2 ms?
	PORTB = 0x00;
	__delay32(600000-60000); // 18 ms?
    }
}
If my understandings are correct, it should start the motor at 0 speed (1ms pulse) for a few seconds, then go to full speed ( 2ms pulse)

I'm using a 16MHz crystal, powering my ESC at 12V, 2A plug and my pic at 5V, 1A.
The 3 wire cable from the ESC I connected like this:
brown - vss
red - 5v
yellow - RB0 port

The esc details specify that it 480Hz+ high refresh rates but I did not understood how to use this

The motor doesn't start, it sometimes starts beeping in pairs of two

Can anyone tell me where did I go wrong?

sorry if I'm a hard-headed newb in advance
 

THE_RB

Joined Feb 11, 2008
5,438
You need to check your delay times.

Your C compiler should have an easier delay function.

Does it have Delay_mS() or Delay_uS() functions?

Otherwise, if you really want to do the job properly it is best to use one of the hardware timer modules to generate the periods. :)
 

Thread Starter

alexix

Joined Mar 27, 2014
5
So do you think other then delay my stuff is ok?

I'm using XC16 compiler from MPLABX and this delay function is the only one that I found, it should take clock cycles as paramether, I took an example from the internet where 15000000 was 0.5 seconds, so I don't know if it applies correctly for me.
 

THE_RB

Joined Feb 11, 2008
5,438
The task you are attempting is to generate HI pulse period of exact duration between 1000uS and 2000uS (which controls motor ESC speed), and a LO period of approx 20mS (LO period deson't matter that much).

It would help a great deal if you have some way to view the output pulses, like a 'scope.

Without a 'scope you will be working blind and guessing if your code is making the right periods.
:)
 

Thread Starter

alexix

Joined Mar 27, 2014
5
I found out that I can use __delay_ms but I had to configure my OSC first.

I got the bitch spinning :D thank you
 

fernan82

Joined Apr 19, 2014
26
Unless that is all you're doing (in which case the dsPIC is way overkill for your project), you might want to use the PWM module on your chip.
 
Top