I’m research around two years about multicopters and read a lot of aerodynamics of fly in theory.
So I learned everything about it.
Now I would like to do some practice in real world and i had many dificulties and issues in it.
I’m programming about nine years on 8-Bit microchip PIC18F/16F mcu’s, assembler or any language doesnt matter for me, CCS C for 16F, hi-tech C for 18F series.
I create many projects with that mcu’s.
So, for a quadcopter or any multirotor projects, microchips mcu’s are really bad for it, 16-bit PIC24 and dsPIC’s too!
Anyway
I want to;
1-) Generate a 250Hz PWM signal and change the dutycycle of the PWM signal between 1000us-2000us.
2-) Reading over hardware based I2C multiple sensors (BMP180, MPU6050 or L3G4200D, HMC5338)
3-) USART/UART with HC-05 bluetooth module @9600baud (no more higher or slower!)
4-) Double and float type variables, use in division and multiply math even sin cos atan and atan2 calculations.
Is this possible with stm32duino?
I bought BAITE maple mini board. I know this is a clone but it works well.
I will really learn KEIL or IAR for stm32 , but I have no more time to finish my project.
Thanks a lot
and sorry for my bad english :/
I want to;
1-) Generate a 250Hz PWM signal and change the dutycycle of the PWM signal between 1000us-2000us.
2-) Reading over hardware based I2C multiple sensors (BMP180, MPU6050 or L3G4200D, HMC5338)
3-) USART/UART with HC-05 bluetooth module @9600baud (no more higher or slower!)
4-) Double and float type variables, use in division and multiply math even sin cos atan and atan2 calculations.
http://www.dx.com/p/9dof-stm32f103-mpu6 … dMdtLK6c1I
Personally, the entire concern about math functions may be a non-issue but you should really find some existing codebase and start there rather than try and build all from scratch. If the existing codebase is inadequate, then you have an opportunity to analyze and determine if it can be “fixed”. When you start from scratch, it is difficult to know if your approach is adequate or inadequate until after a significant amount of time has been invested.
https://www.youtube.com/watch?v=GMPCwHHtkA0
The control board uses STM32F103C8 running at 48MHz as main processor and MPU6050. The sample rate for MPU6050 accel and gyro data is 500Hz and PID controller is 200Hz. Due to the constrain of +-40 degree of inclination, sometimes the quadcopter cannot recover from dramatic situation.
Cut & Paste from a few Google links:
Openpilot: http://www.rcgroups.com/forums/showthread.php?t=2456739
Firmwares currently working for this “board”:
Baseflight: http://www.multiwii.com/forum/download/file.php?id=3364
CleanFlight: https://github.com/cleanflight/cleanfli … _CJMCU.hex
stm32f103 is fine for my project in timing critics. thats not the problem any more. i2c there is also any problem at now.
but in the PWM i’m still in problem.
i search many things about changeing the pwm period of the servo library, it pretty easy on arduino uno because of the 8-bit architechture of the atmel mcus. but when i try to change the period on servo library from stm32 i’m confuse to what to change in there. because it seems the same servo library each atmega and stm32.
Is there anyone to be able make this usefull for everyone to change period and dutycycle on PWM?
I will use the pwm output to controlling ESC. The default servo library has 100hz (20ms period) pwm. But 20ms for a multirotor control is very slow. I need least 250hz to run the ESC for the best update the motors speed.
<…>
I will use the pwm output to controlling ESC. The default servo library has 100hz (20ms period) pwm. But 20ms for a multirotor control is very slow. I need least 250hz to run the ESC for the best update the motors speed.
I used HC-05 to increase and decrease the dutycycle.
At first I configure the hardware timer and select timer2 and their pwm pins like on the pin description, pins are 11,10,9 and 8.
the code is:
HardwareTimer timer( 2 );
byte b=0;
uimt16 DUTY=14484;
void setup()
{
pinMode(11, PWM);
pinMode(10, PWM);
pinMode(9, PWM);
pinMode(8, PWM);
timer.pause ();
timer.setPeriod (4000);
timer.refresh ();
timer.resume ();
Serial1.begin (9600);
Serial2.println("DUTY++ <a> | DUTY-- <b> ");
}
void echoCharacter ()
{
int numUnread = Serial1.available();
if (numUnread > 0 )
{
b = Serial1.read ();
Serial2.println(b);
}
if ( b=='a' )
{
DUTY=DUTY+100;
b='\0';
}
if ( b=='b' )
{
DUTY=DUTY-100;
b='\0';
}
}
void loop ()
{
echoCharacter ();
pwmWrite (11, DUTY);
pwmWrite (10, DUTY);
pwmWrite (9, DUTY);
pwmWrite (8, DUTY);
}
That said, I think that in your example, the timer will no longer count from 1 to 65535, but to some smaller value which you can read back with timer.getOverflow(). The way I understand it, this value corresponds now to the 100% duty cycle instead of 65535, so timer.getOverflow()/4 should get you 1ms duty cycle from the 250Hz signal.
If the 250Hz is not critical, you should maybe just change the channel’s prescaler value, as mrburnette suggested, without changing the period. Then you can still assume 65535 counts will correspond to a 100% duty cycle.
Also on leaflabs mapple wiki there are hardwaretimer topic. Under there are explained these things such setOverlow and setPrescale fonctions how to use. Instrad of these fumctions there is one more fontcion too , setPeriod function. This function sets the prescale and overflow values automaticly over what i gave in setPeriod value in microseconds.
When I change the line in timer.setPeriod (4000) to timer.setPeriod (8000) , pwmWrite() duty is same 14484, ESC’s are entering setup up mode while startup the quadcopter. ESC’s are enter only when powerup whit 2mSec duty is entered in it. So that seems i got the right duty and period from the maple mini. But im not sure because of the pwmWrite duty value is not what i calculate , 14484, if must around 16000~.
I’m gonna try to read the timer.setOverflow value.
I understand that pwmWrite() duty value must equal or less then timer.setOverflow () value.
So pwmWrite (9,14400);
Gives 1 ms pulse, which I confirmed on my LogicAnalyzer
<…>
Gives 1 ms pulse, which I confirmed on my LogicAnalyzer
mine is an Open Workbench Logic Sniffer, had it a fair few years.
it’s trite, but a picture is worth a thousand lines of debug info
stephen
I’d recommend a scope in preference to a logic analyser.
I have a DSO with 16 channel logic analyser, but 90% of the time I dont need to plug in and configure the logic module.
For SPI and I2C, a dual channel DSO can view clock and data, in enough detail to figure out what you are doing wrong.
Plus with a scope you can see things like supply noise, measure voltages, etc.
If the scope didnt have the logic analyser, however, I’d probably have ended up buying a separate / cheap analyser e.g. like Open Bench one
http://sigrok.org/wiki/Lcsoft_Mini_Board
http://sigrok.org/wiki/ARMFLY_Mini-Logic
They are all some kind of clones of Saleae.
Then, install sigrok, sigrock-cli and pulseview, you will be able to do logic capture at low cost. ![]()
So pwmWrite (9,14400);
Gives 1 ms pulse, which I confirmed on my LogicAnalyzer
<…>
For SPI and I2C, a dual channel DSO can view clock and data, in enough detail to figure out what you are doing wrong.
<…>
I’ve plans on doing something similar when I can get some free time.
A couple of things you may wish to change.
MPU9150 is deprecated, use the MPU9250 instead, its in the same package but has some minor improvements and a few pin changes.
the BMP180 gives rather noisy results at the levels required for a quad copter, i would instead suggest using something like a MS5611 which offers much more accuate readings.
PWM for ESC’s is great, but take a look at oneshot. it may help you with some of your timing loops, as well as making your motors more responsive. (Alternatively the 400Hz rate of the SimonK flashed ESC’s is more responsive than the stock 200Hz rate)
Yet another point, if you are looking at receivers, take a look at cPPM its an analogue protocal that supports 8 RX channels over 1 wire.
Look at saleae clones in aliexpress or ebay. They are very cheap, and definitely worth the cost. I have one that I have used perhaps 3 times so far, but the hours it save me those 3 times more than paid for it.
Thanks for your advise. i did like that and bought a clone of saleae and it works good ![]()
FlyMaple ( Product Link )
If you are going to integrate 10DOF IMU on your project, why don’t you use FlyMaple for prototype. Passing to coding quickly will give you some time. I used to have this board and it’s so perfectly designed and produced. Consider it as a development board if you need IMU stuff! (+ there is a demo code available)
AfroFlight Naze32 ( Product Link )
I love those small STM32 boards combined with IMU sensors. This is one of the smallest one with 36 x 36 mm and 5.3 gr! STM32F103CB is used with MPU6050. Non soldered pins are available to work with. RTC is not included.
On the frame I have a maple mini, connected to a nRF24 for communications with the transmitter, two MPU6050 for angle measurement ( DMP for Pitch and Roll and gyro’s only for Yaw) , a BMP280 for altitudes above 300 cm, a HC-SR04 as ultrasoon altitude measurement below 300 cm.
I wrote my own PID subroutines.
I also built a transmitter based upon the maple mini and RF24
I used the hardware timers 1 and 3 with adapted settings for 490 Hz ESC pulses.
The automated altitude leveling is under construction/fine tuning PID constants.
Only draw back is the fact that the hardwire timers sometimes stop functioning, a refresh and resume is used to start them again, but I haven’t been able to discover the reason for this last issue
It isn’t the most elegant solutions, but it helps keeping the quadcopter int he air
If anyone has seen this behaviour before and got a solution I am very interested to hear/see it.

