fyaman66 1 Posted February 2, 2016 Share Posted February 2, 2016 Hello, I wrote a very simple PWM Code for my Brushless DC Motor (incl. ESC) and it works very good (I don't use any Potentiometers.): int motorPin = PF_1; void setup() { pinMode(motorPin, OUTPUT);} void loop() { analogWrite(motorPin, HIGH); delayMicroseconds(1000); analogWrite(motorPin, LOW); delayMicroseconds(19000);} I need 50Hz (1/50=20us). The Motor breaks when the first delay is "1000us" and the second is "19000us". The Motor arrives highspeed when the first delay is "2000us" and the second is "18000us" So my dutycycle should be between 5 - 10% What i need is this PWM Signal without any delays. Is there any way to create a PWM without delays? Thank you very much. greetings, Yaman Quote Link to post Share on other sites
L.R.A 78 Posted February 2, 2016 Share Posted February 2, 2016 I don't get why you are even using delays.Could you please explain a bit on that? Maybe with a time diagram of the signals? fyaman66 1 Quote Link to post Share on other sites
Fmilburn 446 Posted February 2, 2016 Share Posted February 2, 2016 @@fyaman66 You do not appear to be using analogWrite correctly. The general form is analogWrite(pin, value) where value is the duty cycle from 0 (off) to 255 (always on). When you specify HIGH you are making the value 1 or barely on. It may be you meant to use digitalWrite to create PWM. As LRA says, using delay doesn't make much sense here. Read this thread and see if it does what you are trying to do: http://forum.43oh.com/topic/5765-analogwrite-precision-question/ energia and fyaman66 2 Quote Link to post Share on other sites
fyaman66 1 Posted February 3, 2016 Author Share Posted February 3, 2016 I don't get why you are even using delays. Could you please explain a bit on that? Maybe with a time diagram of the signals? Hi, i use the delays to determine the frequency of 50hz (total delay = 20us -> 1/50hz) and also to determine the duty cycle between 5% - 10% (this is the range where the bldc Motor starts to spin) Quote Link to post Share on other sites
fyaman66 1 Posted February 3, 2016 Author Share Posted February 3, 2016 Hello, @Fmilburn Thanks alot. I found the solution in the link you posted this worked for me: #include <wiring_analog.c> void setup() { pinMode(PL_4, OUTPUT); PWMWrite(PL_4,1000,50,50); // PWMWrite(PINnumber, number of steps, dutycycle, frequency); } Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.