Hi @runger I have got the ADC reading correctly, I learnt you can’t use pinmode in the setup ( took me a while to figure that out ) I can’t get PWM to work at all.
If I use:
I get an error no timer found on pin 32, I suspect there is no timer spare or can be configured for that pin. I have tried using pin mode output etc with no luck, even analogwrite doesn’t work.
On another note I have noticed the controller can get into an uncontrollable state, even disable and enable again doesn’t fix it, I have to do power cycle for it to come right. When it get’s in this state I have noticed the voltage Q and D will go to the max ( 12v in my case ) and not go back down, the q stays at 12v and d changes and motors goes nuts. To get in this state happens if the speed is to fast and goes out of sync or motor disabled during movement ( not at all times ) I would have thought when you disable the motor all these values should be reset? It’s like the PID keeps calculating and winding up even though the motor isn’t running.
It sounds like there is no timer on this pin. Although it might be worth checking the PinMap_TIM in the board’s files, if you can manage to do that. Users have been reporting problems with commented out lines in the PinMap_TIM leading to timers which are actually present not being found.
This can be due to several issues.
Firstly, be careful. Suddenly stopping a running motor will cause large inductive spikes, which the B-G431-ESC1 seems to be poorly protected against. Don’t fry your board!
Even if they don’t cause permanent damage, they can cause things to go out of whack and the MCU to freeze or reset.
If the MCU is running, Serial output continues, but the behaviour is as you describe, then it is possible that the sensor data got messed up - this can be again due to the voltage spike, or it can be due to the very fast change in speed causing the sensor’s bandwidth to be exceeded. For absolute sensors such as SPI or I2C based magnetic sensors, this will fix itself quickly and should not lead to the problems you describe. For encoders or hall sensors, missing some steps means the angle is permanently wrong thereafter - I suppose this could be what’s happening to you?
Unless I looked wrong, pin 32 is PA_15. There is a big problem with the PeripheralPins_B_G431B_ESC1.c file, where most of the timer pins are commented out (even if they exist and are available). That has nothing to do with the options being greyed out (that is a VScode UI issue). The variant files for the G431 ESC are improperly commented out.
Go into that file, uncomment line 131 (or 132 if you plan to use TIM8 instead of the default TIM2 assigned to PA15) and recompile everything.
There are a lot of weird things happening with the G431 ESC pin naming at the moment…