Society of Robots - Robot Forum
Electronics => Electronics => Topic started by: saliraza on December 07, 2008, 04:45:35 PM
-
Hello,
I am trying to control 4 individual BLDC motors from my Axon (ATMega640) and need to discuss some ideas. The BLDC motors connected to their ESCs are controlled similar to the Servos. The 20ms PWM signal with the pulse durations b/w 1ms to 2ms works exactly like how it works with Servos. The Axon can control upto 29 Servos, however if each servo/BLDC requires individual PWM control then we need to assign a Timer to each PWM channel. We have only 6 Timers 2(8-bit) and 4(16-bit).
How can one achieve 29 Servos to be controlled? My guess is either by assigning same Timers or via software interrupts.
As I need to individually control 4 BLDC only, I believe I may need to assign the 4 (16-bit) Timers for that job. The unease about this case is that I cannot have anymore 16-bit Timer based operations.
Is there any other way that I am unaware about?
Regards,
Ali Raza.
-
Ali,
I am certainly not the expert, but I recently set up my AXON board to control two servos.
It takes 1 (ONE) timer channel to get my two PWM signals out to servos. Some of the timers can do 3 PWM signals I beleive and some can only do one on these boards. Read more in the
So, with code like this:
PWM_Init_timer3_E3(10);
PWM_Init_timer3_E4(10);
delay_ms(50);
PWM_timer3_On_E3();
PWM_timer3_On_E4();
delay_ms(50);
PWM_timer3_Set_E3(SERVO_CENTER);
PWM_timer3_Set_E4(SERVO_CENTER);
delay_ms(50);
I have set up two different PINS to have separate PWM signals through one timer and one interrupt. I have also centered the servos with a default value.
Then, this code:
void go_forward(void)
{
PWM_timer3_Set_E3(SERVO_CENTER-SERVO_FULL_SPEED);
PWM_timer3_Set_E4(SERVO_CENTER+SERVO_FULL_SPEED);
}
Is what I use for a set-and-forget forward motion. I have a similar one for stop and backward.
This is basically what you need to do but you'll need to use 2 timers I believe with the four independent signals spread across them.
This is a comment section from timer640.c
/*
ATmega640: Four 8-bit PWM Channels, Six/Twelve PWM
Channels with Programmable Resolution from 2 to 16 Bits
PWM pins on Axon:
OC0A B7 (not connected)
OC0B G5 (attached to button)
OC1A B5 (not connected)
OC1B B6 (attached to green LED)
OC1C B7 (not connected)
OC2A B4 (not connected)
OC2B H6
OC3A E3
OC3B E4
OC3C E5
OC4A H3
OC4B H4
OC4C H5
OC5A L3 (not connected)
OC5B L4 (not connected)
OC5C L5 (not connected)
explanations:
http://www.societyofrobots.com/robotforum/index.php?topic=1827.0
http://www.societyofrobots.com/robotforum/index.php?topic=5590.0
If you use this, then you cannot use the associated timers for other things.
H6 uses timer2
E3-5 uses timer3
H3-5 uses timer4
Unfortunately, the 3 pins that use timer5 are not connected on the Axon board, so they are
not available for PWM. The upside is that timer5 is available for other use without interference.
*/
Hopefully this helps.
Doug
-
You can control up to 6 servos using PWM:
http://www.societyofrobots.com/axon/axon_function_list.shtml#pwm
note: The current code has a bug on H3, H4, and H5 that prevents delay_ms() from working. Still trying to figure that out, so avoid those pins for now ;D
-
Hello Dscrimager, and Admin,
Thank you very much for your replies and help. I am looking at the codes and the links you guys have provided. I am not new to PWM just that my previous implementations were done on PIC controllers. I am now using Axon to replace my PIC board.
There are two things that are getting mixed-up, one is servo control and the other is PWM, and to make things more complicated both can be done either by timer operation or via software (delay) control.
I would greatly appreciate if I can get some help related to Axon, for controlling my BLDC motors (works exactly like servo) using the built-in timer based PWM control. What I'm trying to do is a free running system where once the system is initialized I can give (via serial input) 4 values for setting the duty cycle of each of the motor. The PWM setup is to provide signals of 20ms where the duty cycle ranges from 1ms (low) to 2ms(high). The system needs to be armed first where I have to give commands in the following sequence:
Low duty cycle (say 2 sec)
High duty cycle (2 sec)
Low duty cycle (2 sec)
this sequence arms the ESC's of my BLDC motors
once this is done I am running a free running loop where it reads from the serial input for the duty cycle values for the four motors and apply that duty cycle.
I am confused due to two different approaches, one is below in this link
http://www.societyofrobots.com/member_tutorials/node/231
and the second
http://www.societyofrobots.com/axon/axon_function_list.shtml#pwm
Please help!
Regards,
Ali Raza
-
Sorry for the late response . . . I am not quite sure what you need help with.
So you want the Axon to get serial commands, then convert those commands to PWM, right?
Here is an example of serial control:
http://erobots.blogspot.com/2008/08/bluetooth-controlled-lights.html
And here is PWM for servo code:
http://www.societyofrobots.com/robotforum/index.php?topic=5590.0
Does that help?