sim- / tgy

tgy -- Open Source Firmware for ATmega-based Brushless ESCs
http://0x.ca/tgy/
689 stars 386 forks source link

How to use I2C, AfroEsc 30A #64

Open Werner-Prbk opened 10 years ago

Werner-Prbk commented 10 years ago

Hello,

I have some problems getting started with the i2c communication. Actually i have no idea how the protocol is implemented. Documentation of AfroEsc (rev3, nfet) says: Arm at 0 Start at 1 Max Power at 247

I couldn't find any documentation for the simonK firmware. Has anyone here used this firmware with i2c communication?

I'm pretty sure that wiring and i2c master implementation is correct, because a fork (https://github.com/balrog-kun/tgy/) implements a simple i2c protocol and this is working right (but there are other problems, so i want to use the original simonK fw).

sim- commented 10 years ago

Hello!

This implementation is intended to work (and tested) with MK (MikroKopter) flight controllers. It isn't the prettiest or most useful implementation, but it works for this purpose.

For basic use, the protocol is very simple. The only gotcha is that it is processed as the normal RC pulse input is, and so timing is important. You must sent throttle commands at at last 31Hz-ish to avoid hitting the safety timeout, and you must send a series of 0-power commands to start in order to "arm" the ESC. This happens naturally with the MK flight controller, but may be a bit of a nuisance for just tinkering.

Another issue is that there is no way to really set the i2c ID without changing the flash anyway, so perhaps using stock software isn't going to work unless you use separate buses per ESC or are using it for a different application.

However, for basic usage, you can literally just send the command byte (as documented above and in your post) to address 0x52. If you sent 0 first to arm, and keep the command going (particularly when you want power), you should have success.

For more details on balrog's implementation, see http://www.rcgroups.com/forums/showthread.php?t=2032252 .

Werner-Prbk commented 10 years ago

Hi.

Thank you for your quick response. After a few hours of debugging (thank god for RED_on) i figured out that i have some problems with a timeout in i_rc_puls_rx. I had to comment out following three instructions and now communication is working...

i_rc_puls_rx:
rcall evaluate_rc_init lds YL, rc_duty_l lds YH, rc_duty_h adiw YL, 0 ; Test for zero brne i_rc_puls1 ; ldi temp1, 10 ; wait for this count of receiving power off ; cp rc_timeout, temp1 ; brlo i_rc_puls2

Motor is running but wont reach max power at 247. Do i have to match motor and esc?

Balrog's implementation was really easy to use because omitting the whole MK stuff. But i had serious problems with sync loss. Sometimes motor stopped at full speed and i got the famous white smoke. Props were flying around... So i decided to go back to the original implementation. The motor is a Emax MT1806 2280KV.

sim- commented 10 years ago

Hmm, I mean to go through and merge what I can of his work. The only thing I can think of as possibly more risky is the blind commutation stuff which is necessary to use the ADC while we would otherwise be using the input mux for the comparator.

If you are running a low KV and low voltage setup, it may not reach full duty cycle. Otherwise, I'm not sure what could be doing this. Does it stop increasing in speed at a certain level, or is it just that the scaling is wrong?

Werner-Prbk commented 10 years ago

It turned out that i misunderstood the input data format. After a few tests i found out that the motor thrust reaches 310 gram at 247. With Balrogs firmware i got 370 gram at full speed, but then it crashed... so 310 gram is ok for me :)

Do you have any idea why i had to comment out the three lines of code?