1. Although the software has been completed there are still some problems with power supply.
I supply power with battery via USB. The st-link part works and the main part with STM32L476 chip does not.
It appears that only PWR_EN is needed to enable the USB power. But it is not the case for Nucleo-F401 after test.
The power supply is provided either by the host PC through the USB cable, or by an external source: VIN (7V-12V), E5V (5V) or +3.3V power supply pins on CN6 or CN7.
Then I change to VIN. There are three external power input, VIN, E5V, +3.3V. For VIN, 7-12V is required. In my hardware test, 5.25V works fine. Since the specification of LD1117 can handle such power input.
The +3.3V and VIN is accessible in arduino compatible connector CN6, But E5V is only accessible in Morpho connector CN7.
2. Another problem comes that PWM can not drive the L298N even the code is OK. I think the PWM can not response to PWM in higher frequency. Make the switch frequency slower can solve the problem.
I use digitalwrite to make it work and change the Switch Part as follows,
DigitalOut motorA(A5, 0); DigitalOut motorB(A4, 0);
... ...
switch (flycontrol) { case 0: // Stop pwml=0; pwmr=0; motorA=0; motorB=0; pc.printf("\r\nflycontrol=%d\r\n",flycontrol); break; case 1: //Fly pwml=PWM_FLY; pwmr=PWM_FLY; motorA=1; motorB=1; pc.printf("\r\nflycontrol=%d\r\n",flycontrol); break; case 2: //turn left pwml=pwml-PWM_DELTA; pwmr=pwmr+PWM_DELTA; motorA=0; motorB=1; pc.printf("\r\nflycontrol=%d\r\n",flycontrol); break; case '3': //turn right pwml=pwml+PWM_DELTA; pwmr=pwmr-PWM_DELTA; motorA=1; motorB=0; pc.printf("\r\nflycontrol=%d\r\n",flycontrol); break; case 4: //Speed up pwml=pwml+PWM_DELTA; pwmr=pwmr+PWM_DELTA; pc.printf("\r\nflycontrol=%d\r\n",flycontrol); break; case 6: //Speed down pwml=pwml-PWM_DELTA; pwmr=pwmr-PWM_DELTA; pc.printf("\r\nflycontrol=%d\r\n",flycontrol); break; default: // Nothing change if not 1~6 pwml=pwml; pwmr=pwmr; break; }
3. Then it works fine. I can control both motors from mobile. The rest work is mechanical part. I will make it in last blog.