ESC needs 50hz pwm i.e, 2000us period
Embed:
(wiki syntax)
Show/hide line numbers
main.cpp
00001 /* mbed Microcontroller Library 00002 * Copyright (c) 2019 ARM Limited 00003 * SPDX-License-Identifier: Apache-2.0 00004 */ 00005 //simple code for testing effect of pwm update rate of on motor performance 00006 //this is code for update at 2300us 00007 //increment function is called at intervals of 2300us 00008 //or u can use your button to increment at your requirement 00009 #include "mbed.h" 00010 #include "platform/mbed_thread.h" 00011 00012 int i=1000; 00013 Ticker timer; 00014 00015 PwmOut u(PE_9);//create an object u associated with your pin u need pwm from(PE_9 in my case) 00016 void incr(void){ 00017 if(i>2000) 00018 i=1800; 00019 i++; 00020 } 00021 int main() 00022 00023 { 00024 u.pulsewidth_us(2000); 00025 wait(4); 00026 u.pulsewidth_us(1000); 00027 wait(3); 00028 00029 u.period_us(20000);//set frequency of pwm to 50hz as ESC works on 50Hz 00030 00031 timer.attach_us(&incr,2300); 00032 // Initialise the digital pin LED1 as an output 00033 DigitalOut led(LED1); 00034 00035 while (true) { 00036 u.pulsewidth_us(i); 00037 00038 } 00039 }
Generated on Sun Jul 31 2022 06:17:29 by
1.7.2