sim- / tgy

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

MOTOR_BRAKE only works for PWM and not UART or I2C? #60

Open danhouldsworth opened 9 years ago

danhouldsworth commented 9 years ago

Hi Simon,

It looks like the only place that the Brake settings (MOTOR_BRAKE) are queried is from within the PWM conditional code:

.if USE_ICP || USE_INT0
evaluate_rc_puls:
...
puls_zero_brake:
        .if MOTOR_BRAKE
        ldi YL, 1
        sts brake_want, YL      ; Set desired brake to 1 (neutral brake)
        .endif
...
.endif

Does this mean that Brake settings (LOW_BRAKE and MOTOR_BRAKE) will only have effect when using PWM as an input method and not when using I2C or UART?

Let me know if I've missed the point. If not, I'm happy to have a go at submitting a patch if you can confirm the above and give me any pointers of issues to look out for...

Thanks!

sim- commented 9 years ago

Hi Dan,

You are right. The i2c and uart inputs jump to rc_do_scale after receiving the input, which is already after the code that sets brake_want. I suppose that could be rejiggered around to check after the scaling instead of before, but only for neutral brake, since otherwise the scaling clips the low brake. How exactly did you want it to work?

danhouldsworth commented 9 years ago

Hi Simon

Thanks for picking this up. I've really enjoyed, and have learned loads working with your code base.

(Admittedly, I haven't had a chance to work on drones/ESCs for the last few months so my thoughts are a little rusty...!)

I think what prompted my query is having bought lots of AfroESCs I wanted to play around with using UART to see if I could improve on the update rates.

Roughly, PWM sends an integer between 1000-2000 (which rounding up is 2bytes) every 2.5ms, so 800Bytes per second. I forget what UART speeds we can get reliably between the Atmel / ARM flight controller and the ESC but it should confidently be well above 800Bytes per second(?) in which case we would have higher refresh rates of 1000Hz+ with the same granular precision of input.

I know the UART code on the ESC is only looking for a value 0-255 so for now we may have less precision but I was thinking if we simply scaled this across the 2byte 1000-2000 PWM range then all the braking logic (low brake and neutral brake) could be the same code?

Let me know if that makes sense?

Many thanks!

On 14 January 2015 01:16:42 GMT+00:00, Simon Kirby notifications@github.com wrote:

Hi Dan,

You are right. The i2c and uart inputs jump to rc_do_scale after receiving the input, which is already after the code that sets brake_want. I suppose that could be rejiggered around to check after the scaling instead of before, but only for neutral brake, since otherwise the scaling clips the low brake. How exactly did you want it to work?


Reply to this email directly or view it on GitHub: https://github.com/sim-/tgy/issues/60#issuecomment-69853484

Sent from my Android device with K-9 Mail. Please excuse my brevity.