If you live in Malaysia and Cytron is one of your resources, you should have seen all those expensive brush less motors called Vexta. They come with a gearbox and a speed controller.
I looked at the data sheet and I did not see anything about PWM, so I tried to use PWM to control it and I failed. I was using a roughly 60KHz PWM and it did not work. I tried with 16MHz and I am getting a very good result from them. I am using an AVR board which has an Atmega 1280 on it.
I just wrote the following program to make it work.
////////////////////
int a=0;
while(1)
{
OCR0A=a;
OCR0B=a;
a+=10;
delay_ms(3000); //delay_us(500)
if(a>240)
{
a=0;
}
}
//////////////////////
necessary registers are the following:
PORTB=0x00;
DDRB=0x80;
TCCR0A=0x83;
TCCR0B=0x01;
TCNT0=0x00;
OCR0A=0x00;
OCR0B=0x00;
Keep in mind that I was using a 16MHz clock.
There is something else that I have to share, in the catalog there is a page called connection and operation, in that page all on are indicating gnd and all off the indicate +5 (High). (I don't know why)
So in order to run it with PWM, this is what you do with the speed controller:
PIN 1: not connected
PIN 2: not connected
PIN 3: GND
PIN 4: GND
PIN 5: PWM
PIN 6: not connected
PIN 7: +5V (HIGH)
PIN 8: +5V (HIGH)
PIN 9: GND for clockwise. 1 for counter clockwise
PIN 10: GND
PIN 11: GND
This is the video of the Vexta motor running.
I made this blog to share some of what I experienced.It is mostly about my quad. which you can see in the picture.
Wednesday, 21 March 2012
Saturday, 10 March 2012
Review on L6203 Full Bridge Driver
This is an amazing motor driver. It has temperature protector which really works and cut down the current. One of the best thing is that even at high temperature it does not cut the whole current, it will bring down the current. This can be good for the condition where you have to apply force but your motor is stalled for some time.
I have never had any problem using L6203, and honesty it is hard to burn them. To give you an idea, once I connect all pins in opposite order and it did not burnt. The other time I connected the Vs to GND and GND to 36V and it is still working, although it was drawing 3 A. It has even short circuit protector for outputs, which means that even by short circuiting out 1 and 2, nothing bad going to happen. (I have never tried though)
The only thing which I found important is that you can't use Vref as a HIGH for input 1 and input 2. I am not sure why, but I am sure from my real life experience.
You may use Vref for enable but not for inputs.
This is how I use my L6203:
1: Output 2 which is connected to a 15nF cap and one of the wires coming from motor. (the other side cap is connected to boot2)
2: Supply voltage that you want to run motor with it
3: Output 1 which is connected to a 15nF cap and the other wire coming from motor. (the other side cap is connected to boot1)
4: Boot 1. This is connected to the other side of 15nF cap that you have connected to out 1
5: Input 1, just make sure you do not connect Vref as a high for inputs
6: Ground
7: Input 2, just make sure you do not connect Vref as a high for inputs
8: Boot 2. This is connected to the other side of 15nF cap that you have connected to out 2
9: Vref, This is a reference voltage around 12 V. You may use this to apply a high to Enable pin and make the L6203 to always be on.
10: Sense, you can connect this directly to ground, if you don't want to get any feedback from current. If you want to get a feedback from current connect a resistor between this pin and ground. Than read the voltage between this pin and resistor.
11: Enable, by adding high to this pin you will turn on L6203
If you want to get the best out of this component just add a heat sink and a fan, then it works forever with high output current.
This component is much better than L298 and L293. I have used them all and I found L6203 much more reliable, specially if you are going to attend a competitions, you can rely on L6203. I have explode L298 and L293 after using them for long time or drawing high current, but never had any issue with L6203.
If you want to control speed of a motor and its direction, you can simply use one of the inputs as a PWM and connect the other input to any I/O of micro controller which is assigned as output. By changing the value of PWM you will change the speed and by changing the value of I/O from Low to High or High to Low you can change the direction.
I have never had any problem using L6203, and honesty it is hard to burn them. To give you an idea, once I connect all pins in opposite order and it did not burnt. The other time I connected the Vs to GND and GND to 36V and it is still working, although it was drawing 3 A. It has even short circuit protector for outputs, which means that even by short circuiting out 1 and 2, nothing bad going to happen. (I have never tried though)
The only thing which I found important is that you can't use Vref as a HIGH for input 1 and input 2. I am not sure why, but I am sure from my real life experience.
You may use Vref for enable but not for inputs.
This is how I use my L6203:
1: Output 2 which is connected to a 15nF cap and one of the wires coming from motor. (the other side cap is connected to boot2)
2: Supply voltage that you want to run motor with it
3: Output 1 which is connected to a 15nF cap and the other wire coming from motor. (the other side cap is connected to boot1)
4: Boot 1. This is connected to the other side of 15nF cap that you have connected to out 1
5: Input 1, just make sure you do not connect Vref as a high for inputs
6: Ground
7: Input 2, just make sure you do not connect Vref as a high for inputs
8: Boot 2. This is connected to the other side of 15nF cap that you have connected to out 2
9: Vref, This is a reference voltage around 12 V. You may use this to apply a high to Enable pin and make the L6203 to always be on.
10: Sense, you can connect this directly to ground, if you don't want to get any feedback from current. If you want to get a feedback from current connect a resistor between this pin and ground. Than read the voltage between this pin and resistor.
11: Enable, by adding high to this pin you will turn on L6203
If you want to get the best out of this component just add a heat sink and a fan, then it works forever with high output current.
This component is much better than L298 and L293. I have used them all and I found L6203 much more reliable, specially if you are going to attend a competitions, you can rely on L6203. I have explode L298 and L293 after using them for long time or drawing high current, but never had any issue with L6203.
If you want to control speed of a motor and its direction, you can simply use one of the inputs as a PWM and connect the other input to any I/O of micro controller which is assigned as output. By changing the value of PWM you will change the speed and by changing the value of I/O from Low to High or High to Low you can change the direction.
Tuesday, 6 March 2012
How To Use Pulse Width Modulation (PWM) To Control Electrical Speed Controller (ESC)?
In this post we will have some specific talk about AVR since I have experience with.
The objective is to make a pulse with period of 10 ms and pulse width less than 2 ms and more than 1 ms. [1ms,2ms].
At first we look at a case where we have an external 16 MHz clock and we are using 16 bits timer.
If you have a 16 MHz clock then the possible clocks for your PWM are the followings:
16/1 = 16 MHz
16/8 = 2 MHz
16/64 = 0.25 MHz = 250kHz
16/256 = 0.0625 MHz = 62.5 kHz
16/1024 = 0.015625 MHz = 15.625 kHz
So now we will find which of the following will gives us 10 ms period.
we start with the one with lowest period which is working at 16 MHz.
1/(16*10^6) * 2^16 = 0.004096 = ~ 4 ms
This is too fast. We need at least 10ms. so we try with 2MHz
1/(2*10^6) * 2^16 = 0.032768 = ~ 33 ms
This means that this timer will give us a period of 33 ms before overflow.
We know that every 1/(2*10^6) timer counts one, therefore our resolution is 1/(2*10^6) = 0.0000005s = 0.5us
10 ms / 0.5 us = 10 ms / 0.0005 ms = 20,000
20,000 indicates that after this number we have to start from zero. (resetting the timer)
1 ms / 0.5 us = 1 ms / 0.0005 ms = 2,000 steps for minimum speed
2 ms / 0.5 us = 2 ms / 0.0005 ms = 4,000 steps for maximum speed
Here I do not want to talk abou PWM I will do it here, so I will just leave the required value of registers in order to achieve what it is explained above:
//defining I/Os as output so later on we will generate the waveform on these pins
// Port B initialization
// Func7=Out Func6=Out Func5=Out Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=0 State6=0 State5=0 State4=T State3=T State2=T State1=T State0=T
PORTB=0x00;
DDRB=0xE0;
// Timer/Counter 1 initialization
// Clock source: System Clock
// Clock value: 2000.000 kHz
// Mode: Fast PWM top=ICR1
// OC1A output: Non-Inv.
// OC1B output: Non-Inv.
// OC1C output: Non-Inv.
// Noise Canceler: Off
// Input Capture on Falling Edge
// Timer 1 Overflow Interrupt: Off
// Input Capture Interrupt: Off
// Compare A Match Interrupt: Off
// Compare B Match Interrupt: Off
// Compare C Match Interrupt: Off
TCCR1A=0xAA;
TCCR1B=0x1A;
TCNT1H=0x00;
TCNT1L=0x00;
ICR1H=0x4E;
ICR1L=0x20;
OCR1AH=0x07;
OCR1AL=0xD0;
OCR1BH=0x07;
OCR1BL=0xD0;
OCR1CH=0x07;
OCR1CL=0xD0;
This will make the PWM to work in the way that we want. (This code was tested in real life) It will give three different PWMs.
Now this is the function that will change the pulse width for output A from timer 1.
void motor_x(unsigned int speed )
{
OCR1AH = speed >> 8;
OCR1AL = speed;
}
The objective is to make a pulse with period of 10 ms and pulse width less than 2 ms and more than 1 ms. [1ms,2ms].
At first we look at a case where we have an external 16 MHz clock and we are using 16 bits timer.
If you have a 16 MHz clock then the possible clocks for your PWM are the followings:
16/1 = 16 MHz
16/8 = 2 MHz
16/64 = 0.25 MHz = 250kHz
16/256 = 0.0625 MHz = 62.5 kHz
16/1024 = 0.015625 MHz = 15.625 kHz
So now we will find which of the following will gives us 10 ms period.
we start with the one with lowest period which is working at 16 MHz.
1/(16*10^6) * 2^16 = 0.004096 = ~ 4 ms
This is too fast. We need at least 10ms. so we try with 2MHz
1/(2*10^6) * 2^16 = 0.032768 = ~ 33 ms
This means that this timer will give us a period of 33 ms before overflow.
We know that every 1/(2*10^6) timer counts one, therefore our resolution is 1/(2*10^6) = 0.0000005s = 0.5us
10 ms / 0.5 us = 10 ms / 0.0005 ms = 20,000
20,000 indicates that after this number we have to start from zero. (resetting the timer)
1 ms / 0.5 us = 1 ms / 0.0005 ms = 2,000 steps for minimum speed
2 ms / 0.5 us = 2 ms / 0.0005 ms = 4,000 steps for maximum speed
Here I do not want to talk abou PWM I will do it here, so I will just leave the required value of registers in order to achieve what it is explained above:
//defining I/Os as output so later on we will generate the waveform on these pins
// Port B initialization
// Func7=Out Func6=Out Func5=Out Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=0 State6=0 State5=0 State4=T State3=T State2=T State1=T State0=T
PORTB=0x00;
DDRB=0xE0;
// Timer/Counter 1 initialization
// Clock source: System Clock
// Clock value: 2000.000 kHz
// Mode: Fast PWM top=ICR1
// OC1A output: Non-Inv.
// OC1B output: Non-Inv.
// OC1C output: Non-Inv.
// Noise Canceler: Off
// Input Capture on Falling Edge
// Timer 1 Overflow Interrupt: Off
// Input Capture Interrupt: Off
// Compare A Match Interrupt: Off
// Compare B Match Interrupt: Off
// Compare C Match Interrupt: Off
TCCR1A=0xAA;
TCCR1B=0x1A;
TCNT1H=0x00;
TCNT1L=0x00;
ICR1H=0x4E;
ICR1L=0x20;
OCR1AH=0x07;
OCR1AL=0xD0;
OCR1BH=0x07;
OCR1BL=0xD0;
OCR1CH=0x07;
OCR1CL=0xD0;
This will make the PWM to work in the way that we want. (This code was tested in real life) It will give three different PWMs.
Now this is the function that will change the pulse width for output A from timer 1.
void motor_x(unsigned int speed )
{
OCR1AH = speed >> 8;
OCR1AL = speed;
}
I guess now you have got the idea, if there was any issue just post your questions in the comments.
How To Use Commercial Electronic Speed Controller (ESC) Without Remote Controller And Receiver?
If you have a remote control and a receiver read here.
I consider that you have a micro controller, ESC and brush-less motor.
This is something for testing so I will talk in general, however some ESCs will give you this information in details in their datasheet. I have just used 4 to 5 different type of ESCs.
Keep in mind that some ESCs are programmable but they are not programmed in same ways but if you are going to program them, full throttle means the maximum speed.
Most ESCs they will capture the maximum and minimum signals before they start running. In order to calibrate your ESC with signals you have; do the following.
1) Turning the ESC on
2) Max signal applied
3) Waiting for some time (4 seconds for my case)
4) Minimum speed
This should be done step by step and you should not delay between steps.
Till now I did not tell you what the signal is. The signal is having period equal to 10ms.
Pulse width is 1ms for minimum speed and 2ms for maximum speed. This is going to work for most ESCs.
This is how your pulse should look like

I consider that you have a micro controller, ESC and brush-less motor.
This is something for testing so I will talk in general, however some ESCs will give you this information in details in their datasheet. I have just used 4 to 5 different type of ESCs.
Keep in mind that some ESCs are programmable but they are not programmed in same ways but if you are going to program them, full throttle means the maximum speed.
Most ESCs they will capture the maximum and minimum signals before they start running. In order to calibrate your ESC with signals you have; do the following.
1) Turning the ESC on
2) Max signal applied
3) Waiting for some time (4 seconds for my case)
4) Minimum speed
This should be done step by step and you should not delay between steps.
Till now I did not tell you what the signal is. The signal is having period equal to 10ms.
Pulse width is 1ms for minimum speed and 2ms for maximum speed. This is going to work for most ESCs.
This is how your pulse should look like

So as you can see that the red line shows the maximum speed and the orange line shows the minimum speed.
As you may noticed the ESC will understand when it is not connected to anywhere since the minimum speed which means no rotation will occur at 1ms pulse width and if you don't have that 1ms then the ESC conclude that there is no signal connection.
I have explain here how you can make a waveform like the one above.
How To Use Commercial Electronic Speed Controller (ESC) With Remote Controller And Receiver?
If you do not have a remote control and/or receiver, read here.
Well, if you have a remote controller and a receiver you just have to connect the wires, and play around with sticks and you will see that the Brush-less motor will start moving. If it did not work follow the following steps:
* If your problem is bad wires, this will not help you.
1) change the connection between motor and the ESC:
In normal ESCs and Motors the wires should be connected from right to left or left to right. By changing the order between these two, you will change the direction that the motor will rotate. You should connect most left coming out of ESC to the most left going to the motor. I have seen motors which does not work this way, the best is to try all combinations by shifting each wire to tight or left. If this did not work go for the next step.
2) flip the connector which connects the receiver to ESC.
You may be able to flip this in many receivers, if you are not able to do so, that means that your connection is right. Keep in mind that usually the middle pin is 5V and the sides are ground and signal. Red is usually chosen for 5V, black or brown for ground and yellow for signal.
3) If it does not work yet, try another channel and move all the sticks.
4) If you have an oscilloscope (a servo motor will do the same in easier manner if you have one), connect it to signal pin of your receiver. If you had a square wave with period of 10ms or something around that, then your remote control and receiver work. If you are lazy to take an oscilloscope just connect a servo. If the servo works, it means remote control and receiver work.
So, now you have to make sure that the brush-less motor or ESC is working. The only way, I know is using another brush-less motor or ESC. If you know a better way leave it in comments.
If you do not have a remote control and/or receiver, read here.
Well, if you have a remote controller and a receiver you just have to connect the wires, and play around with sticks and you will see that the Brush-less motor will start moving. If it did not work follow the following steps:
* If your problem is bad wires, this will not help you.
1) change the connection between motor and the ESC:
In normal ESCs and Motors the wires should be connected from right to left or left to right. By changing the order between these two, you will change the direction that the motor will rotate. You should connect most left coming out of ESC to the most left going to the motor. I have seen motors which does not work this way, the best is to try all combinations by shifting each wire to tight or left. If this did not work go for the next step.
2) flip the connector which connects the receiver to ESC.
You may be able to flip this in many receivers, if you are not able to do so, that means that your connection is right. Keep in mind that usually the middle pin is 5V and the sides are ground and signal. Red is usually chosen for 5V, black or brown for ground and yellow for signal.
3) If it does not work yet, try another channel and move all the sticks.
4) If you have an oscilloscope (a servo motor will do the same in easier manner if you have one), connect it to signal pin of your receiver. If you had a square wave with period of 10ms or something around that, then your remote control and receiver work. If you are lazy to take an oscilloscope just connect a servo. If the servo works, it means remote control and receiver work.
So, now you have to make sure that the brush-less motor or ESC is working. The only way, I know is using another brush-less motor or ESC. If you know a better way leave it in comments.
If you do not have a remote control and/or receiver, read here.
Subscribe to:
Posts (Atom)