camcamfresh / Xiaomi-M365-BLE-Controller-Replacement

Replacing the BLE Controller with a Cellular Controller
143 stars 34 forks source link

"Motor Control" vs "firmware" #13

Closed Teklock closed 5 years ago

Teklock commented 5 years ago

Does anyone else have throttle issues with firmware.ino? It's very strange but in short it don't work. However when I build a firmware out of "Motor Control" Everything works perfect!

BPitts2 commented 5 years ago

Have you reviewed the map, and also checked your grounds? I had to update the map settings for my throttle, it was slightly higher than the existing code. I also had an issue with a stray ground wire that was causing chaos.

On Mon, Jan 28, 2019, 01:14 Teklock <notifications@github.com wrote:

Does anyone else have throttle issues with firmware.ino? It's very strange but in short it don't work. However when I build a firmware out of "Motor Control" Everything works perfect!

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/camcamfresh/Xiaomi-M365-BLE-Controller-Replacement/issues/13, or mute the thread https://github.com/notifications/unsubscribe-auth/AGp40soB9UhbrY1Tz3qCamIurvqtrmrrks5vHpU6gaJpZM4aVQvz .

Teklock commented 5 years ago

I'm glad you asked this! How do I find the limits for the throttle?

BPitts2 commented 5 years ago

I think I wrote a basic sketch to just read the input from the throttle and print to serial. Then I took the min and max values and updated the map.

On Mon, Jan 28, 2019, 12:58 Teklock <notifications@github.com wrote:

I'm glad you asked this! How do I find the limits for the throttle?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/camcamfresh/Xiaomi-M365-BLE-Controller-Replacement/issues/13#issuecomment-458235708, or mute the thread https://github.com/notifications/unsubscribe-auth/AGp40qAYa6ZuE3orhBHGH2XAj8a85Stgks5vHzpigaJpZM4aVQvz .

Teklock commented 5 years ago

I'm a little confused as to why (according to the readme) we're feeding the throttle and brake 5v lines into the Electron's 3.3v analog pins? It's no wonder why everyone's throttle map is jacked up.

camcamfresh commented 5 years ago

The factory halls sensors take an input 5V (you could use 3.3V), but the Electron’s pins are 5V tolerant.

BPitts2 commented 5 years ago

Camcamfresh is correct:

Notes: [1] FT = 5.0V tolerant pins. All pins except A3 and DAC are 5V tolerant (when not in analog mode). If used as a 5V input the pull-up/pull-down resistor must be disabled.

https://docs.particle.io/datasheets/cellular/electron-datasheet/

On Sun, Feb 3, 2019, 12:10 camcamfresh <notifications@github.com wrote:

The factory halls sensors take an input 5V (you could use 3.3V), but the Electron’s pins are 5V tolerant.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/camcamfresh/Xiaomi-M365-BLE-Controller-Replacement/issues/13#issuecomment-460069501, or mute the thread https://github.com/notifications/unsubscribe-auth/AGp40hsPusR0aH30SaxF0Q6z8Zu-Y5oDks5vJxgOgaJpZM4aVQvz .

Teklock commented 5 years ago

I understand the pins are 5v tolerant, but from what I've read on their forums ADC reference voltage comes from the 3.3v supply. I guess for me to better understand, can you explain this line of code.

map(value, 685, 4095, 0x26, 0xC2)

I'm guessing the 4095 is the max (12bit) and 685 is the min?

BPitts2 commented 5 years ago

Yes, that is the analog input from min to max and mapping to the min and max Hex codes. I didn't dig much deeper, but my assumption is that the motor controller is expecting input from a min to max range. In order to have a consistent throttle curve, the analog input is mapped to the min and max Hex.

Anyone feel free to correct me if I'm wrong.

On Mon, Feb 4, 2019, 12:21 Teklock <notifications@github.com wrote:

I understand the pins are 5v tolerant, but from what I've read on their forums ADC reference voltage comes from the 3.3v supply. I guess for me to better understand, can you explain this line of code.

map(value, 685, 4095, 0x26, 0xC2)

I'm guessing the 4095 is the max (12bit) and 685 is the min?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/camcamfresh/Xiaomi-M365-BLE-Controller-Replacement/issues/13#issuecomment-460334281, or mute the thread https://github.com/notifications/unsubscribe-auth/AGp40hVtjBQ4wUM68tH5kPAnjugejg1xks5vKGwjgaJpZM4aVQvz .

Teklock commented 5 years ago

So why is the min 685 when there is no voltage? Shouldn't it be 0?

Teklock commented 5 years ago

Also why would the ESC expect a range from 38 to 194. Where does that range come from?

camcamfresh commented 5 years ago

Yes, that is the analog input from min to max and mapping to the min and max Hex codes. I didn't dig much deeper, but my assumption is that the motor controller is expecting input from a min to max range. In order to have a consistent throttle curve, the analog input is mapped to the min and max Hex. Anyone feel free to correct me if I'm wrong.

From what I remember, the motor controller's minimum acceptable value is 0x26. Anything below that, say 0x00, would cause the motor controller to think that the sensor isn't connected. I do think there is a maximum value for the motor controller too (e.g., it won't accept 0xFF), but I don't remember the exact value something like 0xF0. The above applies to both the brake and throttle sensor.

Also why would the ESC expect a range from 38 to 194. Where does that range come from?

I'm not entirely sure on that. My best guess is that the minimum value ensures that the sensor is connected; for example, if the sensor wires were disconnected the microcontroller could read 0x0 or a smaller value (idk maybe from static from the air or case) like 0x15. As for the maximum value probably the same reason; for example, if the sensor wires were shorted, the sensor could send back 0xFF. When 0xFF is sent as a value, I think the motor controller acts as if the sensors are disconnected. This is just a guess though.

Teklock commented 5 years ago

Makes sense, ty sir!

fyi... I have the throttle working very nicely on a teensy 3.1 with:

map(control, 900, 4095, 0x26, 0xCC);

after you enable 12bit with:

analogReadRes(12);