![]() ![]() Make connections with Arduino and POT according to this schematic diagram. In other words, we will map the digital value measured with analogRead() function into duty cycle. To control duty cycle, we will use a potentiometer with analog channel zero of Arduino. We will use D10 pin of Arduino to get output signal. ![]() In this section, we will learn to generate variable duty cycle PWM. } Proteus Simulation Output Variable Duty Cycle PWM Arduino TCCR1B=_BV(WGM13)|_BV(CS11) /* Activate PWM Phase, frequency correction Mode */įloat frequency=0 /* initially set frequency to zero */ TCCR1A=_BV(COM1A1)|_BV(COM1B1) /* set Fast PWM Mode */ PinMode(outputpin, OUTPUT) /* set as a output put */ * Perform initialization and declarations inside setup() */ void loop()Ĭomplete Code int outputpin=9 /* Assign symbolic name outputpin to D9 PWM pin of Arduino */ The value of frequency gets updated on the PWM pin after every one second. The potentiometer which connects with analog channel zero (A0) of Arduino is used to control set the frequency of the PWM signal. 0.0113 is a factor that restricts the count variable in the range of 10000 to 100000 which results in a frequency range of 10 Hz to 100Hz. Similarly, analogRead() functions reads 0 when voltage is 0V. The analogRead() function reads 1023 when voltage is 5V at the analog pin. However, it finally works and I hope this post will help to save someone a lot of time, stress and grey hair some day.Inside the loop() function, the value of OCR1A is being calculated stepwise according to the required frequency formula given above. ini-file and therefore abandoned the idea, because the documanetation clearly says to use the bluepill ID… Although I tried to use this board ID already yesterday, I think I didn’t try it in combination with the board_re = maple entry in the. ini-file looks like now: Īnd that works like a charm. Instead you have to use a STM32F103C8 (Generic) board when setting up a new project and include the maple core in the platformio.ini file afterwards. It states to use the “bluepill_f103c8” board ID, but that’s wrong because it just doesn’t work. The main problem are the setup instructions for the Blue Pill found on this page. In case it might be of any interest for someone in the future: I (finally) found the solution on my own. Many thanks in advance and my apologies for the lengthy explanation and the maybe crude english, I’m not a native speaker. In case it matters: For uploading I use a FTDI adapter and I’m running PlatformIO on Linux Mint 19.3 Cinnamon. Hours and hours with Google and the search function in this forum couldn’t help me, so can PLEASE someone explain how I can get this running? To configure the PWM output as I need it. Later I also will have to use these functions HardwareTimer timer(X) In short: How can I use the “advanced” functions of the Blue Pill (in comparison with an Arduino Nano), according to the Leaf Labs documentation? For me the whole point at the STM32 MCU is the higher timer and therefore PWM resolution. I get a beautiful square wave with a duty cycle of 50 % and a frequency of 1 kHz (by the way: Why is that? Without modifying the prescaler and/or overflow of the responsible timer, the frequency should be around +/- 500 Hz…) Just for verifying that the upload works correct: If I use a code like this #include ![]() I have also tried to swap the PB6 pin designator with 42 according to the pinout diagram of the Blue Pill, but that doesn’t work either. So in this combination the syntax is accepted, but the pin mapping seems to be wrong. With these two changes, the PWM pin mode and the pwmWrite function are both recognized and the program compiles without a problem, but nothing happens on the specified pin (or any other pin checked with my scope) ini file to the following (found somewhere here in the forum): īoard_build.mcu = stm32f103c8t6 //tested with and without this line makes no difference When I use the same code in the Arduino IDE, it works just fine. The problem: The compiler doesn’t recognize neither the “PWM” pin mode nor the “pwmWrite” function. My platformio.ini file looks like this: Īccording to the Leaf Labs Documentation ( pinMode() - Maple v0.0.12 Documentation ) this should give me a PWM signal with a duty cycle of 50 % at around 500 Hz. Here is the code I’m using for a first test: #include I hope, someone can help me.Īs stated in the topic, I’m using a STM32 Blue Pill with F103C8T6 MCU as development board. ![]() I’m currently trying to switch from Arduino IDE to PlatformIO and have a problem, that drives me nuts. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |