Open Propeller Project #4: Program our ESCs with a Propeller
Ken Gracey
Posts: 7,392
Open Propeller Project #4: Program our Electronic Speed Controllers with a Propeller
Help us ditch the $15 ESC programming card!
Hopefully I'm not wearing out my welcome with these requests.
I mentioned in another thread that we are planning significant performance and assembly improvements to the ELEV-8 and would like to drop the price to under $500. While looking at a costed Bill of Materials (BOM) today, one item stood out like something you'd use once and toss into the junk bin: the $14.99 BESC Programming Card. We all have enough electronic junk already, don't we? And why spend money on something we don't really need?
I introduce what appears on the surface to be an easy Open Propeller Project - emulate the programming card with a Propeller P8X32A and save us all some money. There are some good resources on the internet about doing this with a microcontroller. These cards are used to configure the ESC for the ELEV-8. Typically, you connect the programming card to power and the ESC, press a bunch of buttons that determine the settings, press "OK" and unplug the ESC from the programming card.
There may be a couple of programming "gotchas" in this Open Propeller Project. If somebody had no programming card, they can actually program the ESC by connecting it to a receiver and sending signals from their radio. This means it just takes a series of pulses with some specific timing in between them. But this method has no confirmation of the settings you've chosen. When you use a programming card you can also read the settings from the ESC [I believe, but I'm not certain]. To fully emulate the programming card, we'd also like to read the ESC settings if possible.
When I spoke with Daniel and David about this OPP this afternoon they got excited so it must be a reasonably rewarding project. They would probably love to spend their afternoon on this one, but they have other urgent projects in process that all of us would make a higher priority, like the Propeller 2 FPGA, Spinneret 2, a U-BLOX PAM-7Q GPS Module, etc., so we turn to the community with a new challenge! After all, SRLM mentioned in another thread he was going to other web sites to buy new products [and we certainly want to keep him happy here on his home turf with enough core stuff!].
The Goal
- Create a Spin/ASM (if required) program which provides a PST-based interactive terminal in which the user can configure the settings of an ESC by entering values, and then "downloading" them to the ESC.
- The PST menu choices can be shown by clicking a large picture of the programming card http://www.parallax.com/product/85000.
- Provide an option to read the programmed settings back, also using PST.
- Once we're all happy with the Spin version, we port it to C for use in Simple IDE so we have two versions of the same code.
- Verify that this configuration could be done through the Hoverfly Open board (I can do this part for you since few of us have this board). Maybe somebody could post the schematic in this thread.
Am I expecting a half-dozen people to collaborate on the code and produce a single, final version? Nah...we'll just pick a final version from the thread, do a bit of minor formatting, and call it done. Yet I imagine there would be a lot of collaboration along the way.
Since you need hardware to do this job, I'd be happy to send out about five to six sets of programming cards and ESCs to those interested in the challenge (please have a domestic address!). I'm not sure if motors are needed to do this project but they might provide some kind of "beep" confirmation. I'll include them if required - just let me know by reply.
Just send me a message with the request to participate kgracey@parallax.com. Post your results here on this thread as you proceed.
Thanking you in advance,
Ken Gracey
Comments
This should be easy to get started! I looked into this very thing a while ago and found this link: http://eleccelerator.com/turnigy-esc-programming-card-reverse-engineered/
It includes C/C++ source code for an atmega (not arduino, just the avr compiler). Works for Turnigy BESC Programming Card compatible ESCs.
Some issues/details based on reading threads where this guy posted:
1. The ESCs only go into "programming mode" when they first start up (get power applied) and you signal them appropriately in that startup window, so you can't just put them into programming mode whenever you want.
2. It seems that the only output their current state once at startup, so you can't "read back" what you wrote in without a power cycle to the ESC.
The above might not be rigid. It may be possible to send them a signal to make them switch into programming mode and to read out their current state, but it's something that would need to be figured out.
Edit: After re-reading your post I realized you already linked this same site. Do'h! Anyway, the rest of my message applies.
Need a few more to help out with this OPP.
Ken Gracey
IIRC the esc has to be setat max on powerup (probably some slight delay while the prop powers up wouldbe ok).
Sorry Ken, I have toomuch on the go to look at this for now.
You need to attach the signal pin from the ESC servo connector to prop pin 6 (or change the code to whatever pin you want), and the ground pin from the ESC servo connector (not the battery ground) to ground on the prop board. These are on the servo connector. Then load/run the program and it'll print "Waiting for ESC...". Now attach power to your ESC (the main battery in). The program should print out the settings it read (hex number), then what it sent back (another hex number). Wait for it to print "Done.", then you can disconnect power from the ESC
To change what settings get sent, you need to edit the main PUB at the top of the file.
This is just a quick port to get it working. The comments are all just from the original C code. We can take this and clean it up, and add the PST interactive stuff you described. The hex numbers it prints out can easily be changed into pretty human friendly displays of the settings.
Then it's a matter of documentation, and then you and Parallax can split the savings on each kit
Really, thanks again, Roy.
Ken Gracey
Novel idea.
Way to go!
I come back to this thread the next day had Roy has it all figured out.
@Roy, Would you like any help with this? I think I could (and I am offering) help with any of the above tasks you mentioned. Let me know which task(s) you'd like me to help with.
the programming-card / propeller-code does change parameters. What parameters are offered is based on the firmware of the ESC.
So if the ESC offers no option to choose unidirectional / bidirectional running of the motor you would have to rewrite the firmware.
Maybe you can imagine parameters like mounting different brands of tires on a car. Changing tires is pretty easy.
Changing the firmware is like
If you want to have four wheel-driving you would have to change a lot of mechanical things inside the car that has only two wheel-driving.
best regards
Stefan
I agree with Stefan that this isn't something that could be done using the programming signals.
If one had access to the microcontroller used by the speed controller, then something like what your talking about might be possible. You'd have to know how to program the particular microcontroller and know what signals to send to the on board hardware. From my limited understanding of how brushless motors work, I don't think this would be an easy task.
Your question makes me wonder if a bidirectional ESC could be made from the same hardware as an airplane ESC. My (frequently wrong gut) tells me it should be possible.
The ESC programming going on here is more like selecting settings than truly reprogramming the ESC.
Here's a picture of the programming card being used.
There's some discussion about which settings to use here.
You can not use a card to program in a fwd or reverse unless the speed controller (Esc) is programmed with those options.
However, you can load your own program into an airplane or helicopter Esc using the information on this thread
I believe there is another thread for reprogramming the C8051 speed controllers. Either way, there is plenty of well documented
open source code available for the AVR, C8051, Arduino (avr) and maybe ST micro controllers using C or assembly.
Note: There are no examples of how to add a reverse in the link I provided, but there is examples written in C in this thread.
Once you have reprogrammed the Esc, you could build your own controller to reprogram any options you choose.
Bill M.
I've heard brushless motors will work underwater but I think I'm going to have to try it myself to really believe it. It sure sounds like a cool idea.
What about adding a DPDT switch to two of the three motor power lines? In order to switch the direction a brushless motor is turning, you swap two of the three power lines. This would something easy to program a microcontroller to do. I think this technique would probably work best if the motor was allowed to stop before the direction is changed.
That isn't necessary, some airplane, helicopter, and quadcopter esc's are equipped with a reverse.
They are just not as common as the esc's that offer only one direction.
For example: this HobbyKing 20A BlueSeries Brushless Speed Controller is equipped with a reverse.
It is also one of the esc's that can be flashed with the SimonK firmware.
This older "Mystery Pentium" BLDC Esc is also equipped with a programmable reverse. But it is an older
esc and the newer esc's do not seem to have that option.
Also: I am not sure if it can change direction in flight, or if it is only capable of CW or CCW operation.
However SimonK programed in a "RC Car like Reverse" so that quad copters could fly upside down. Takao also wrote several
examples of an "RC Car like Reverse" for Arduino based esc's and the examples were simpler than you might think.
I have included a spread sheet listing bldc esc's that SimonK's software will flash, and 2 links on re-flashing the
esc. Link 1 Link 2, I recommend you read this one
This is one of Takao's examples of a program including CW & CCW rotation based on throttle input for a motor equipped with hall
sensors.
If you are interested in adding hall sensors to Outrunners 1
adding hall sensors to Outrunners 2
adding hall sensors to Outrunners 3
adding hall sensors to Outrunners 4
The Quadcopter guys may also be interested in link#3. Link #1 is for larger robotic motors.
I have a lot of experience tuning Sea Doo's and Jet Ski's for salt water or fresh water racing. With your own code, you could do the same,
and by building a programmer, you could adjust your motors to be more efficient for either fresh or salt water.
Bill M.
-dan
When it's been done cost-effectively already by the Chinese there's little reason to try to duplicate a low-cost, optimized production effort.
But I'm happy to get rid of the ESC Programming Card. I'm still waiting to hear from David Carrier whether or not the ESCs can be programmed through the OPEN board (there's some buffer circuitry between the I/Os).
Ken Gracey
I used to think that too, but their product is only as good it's software, and as a result 2nd & 3rd time buyers are
purchasing esc's from US and European sources.
I'm at the point in my ELEV-8 build to program my ESC's , but my card is DOA. I want to be green and do it over the ether instead of Parallax sending me a new card.
Jim
Jim,
Yes, I did connect an ESC, program it and then plugged it into the card programmer to see the changes reflected. Interestingly I was unable to monitor the data with my scope. Even on X10 it seems to load the signal line down enough where the ESC won't respond with it attached. I will have to look more into this later.
We still need some help on this important OPP.
I've attached the code we're using which is a modified version of Roy's code from the first page - the same except with a different PST interface. And I've also attached our ESC Programming Test Procedure. We need to get this resolved because we're shipping new ELEV-8 V2s starting next week.
We have three problems. First, this seems to work but only under ideal conditions. Second, there is no verification stage. I've checked ESCs with programming cards after I've run this code and sometimes they're right, other times not. It would be ideal to read back the program settings and display them on PST with a "ESC Passed Programming" message. And finally, we're not all that sure of the actual power arrangement to be perfectly honest. We can get reasonably successful programming rates using a 9VDC power adapter with Vin going to the ESC's signal/power/ground connector with no power attached to the battery side of the ESC. We get slightly better programming success with an external 11VDC power supply connected to the ESC's battery connector and a regulated 5VDC on the ESC's signal/power/ground connector. We should have 100% success with our programming method.
I can send out pairs of ESCs and programming to anybody who wishes to help us obtain this small but important project.
Just send Julia an e-mail with your domestic shipping destination via jquillen@parallax.com and copy me kgracey@parallax.com. Don't use PMs with me, please, as I can hardly stay on top of e-mail without more communication around me.
In the meantime I'm seeking out a programming specification from the supplier. I believe this is the actual model http://www.dys.hk/Download/HW25A30A.pdf. If an R/C radio can program these without a programming card, any microcontroller with compatible logic levels can certainly do the same.
Thanks!
Ken Gracey
I should already have all I need to work on this. I don't mind working on this project, I just don't want to be duplicating someone else's efforts.
I can use a logic analyzer to watch the communication between the programming card and the ESC to see how it queries the ESC for the settings and attempt to replicate this with the Propeller.
I'll get working on this right away unless someone else really wants to do it (it won't hurt my feelings for someone else to do this).
As I said, I already have all the gear so I won't be bothering Julia.
I don't like to burden any of you with this kind of project we should be able to do on our own, but we're really overloaded right now.
Let me know if you need anything whatsoever.
Ken Gracey
Mine is a "Turnigy" card. I don't think I got it from Parallax but I know I've used it with the ELEV-8's ESCs. Besides Turnigy brand ESCs it also works with a lot of HobbyKing ESCs (but not all HobbyKing ESCs can be programmed). I'm not sure what other brands of ESCs it will program.
@Ken, I think Roy's code will make this relatively easy. It looks like the timing could be improved by using synchronized delays rather than fixed delays. My guess is the Spin overhead in places is causing occasional timing glitches. I'm pretty confident this task is within my present skill set.
I doubt it will be needed, but the timing could be made really tight by using PASM.
Parallax documentation states to set battery type to Li-xx, (assuming Li-Po).
The program sets the battery type to NiMh, and LiPo cells to 3.
Confusing.
Hmmm... yeah, very confusing. That setting (LiPo, NiMh) controls the voltages used for high / med / low cutoff values. The LiPo settings are 9.3 / 8.55 / 7.80 for a 3S pack. The NiMh settings would be 7.56 / 5.67 /"not used". Essentially those would be useless, the LiPo would be out of gas long before the cutoff kicked in. I think the Hoverfly documentation is wrong on this one.
-Russ