Go Down

Topic: Generating PWM from PID to control DC motor (Read 4464 times) previous topic - next topic

naeemawan36

please help to generate PWM from PID using arduino i m not good programmer

jremington

1. download the PID library and study the documentation
2. try the Basic Example

naeemawan36

i read that most exmples are in analogwrite but i want to generate using digitalwrite because i want to change the time period of pwm

jremington

Quote
i want to change the time period of pwm
Why would you want to do that?

naeemawan36

actually am working on buck-boost converter to control speed of dc motor so i need to confirm that pwm i sending from arduino is 20khertz

jremington

#5
Sep 06, 2016, 09:06 pm Last Edit: Sep 06, 2016, 09:08 pm by jremington
The timers can be programmed to deliver PWM over a very large range of frequencies. See the MCU data sheet and this tutorial for details.

naeemawan36

i knw timer but i am confused in PID output , that how pid output can be converted into our pwm

naeemawan36

actually its close loop converter with PID feedback

jackrae

#8
Sep 07, 2016, 08:31 am Last Edit: Sep 07, 2016, 09:37 am by jackrae
Feedback isn't PID.  It's what you do with feedback (error signal), via the control algorithm, to create a PID output response.

MarkT

PID is feedback, its not a feedback signal though.  Feedback is the whole caboodle of closed loop
control.

Quote
i knw timer but i am confused in PID output , that how pid output can be converted into our pwm
I don't understand the difficulty - the output is the PWM drive.
Code: [Select]

  analogWrite (pin, pid_output) ;
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

naeemawan36

sir i m confused if i write analogwrite(pin,pid output) then how i configure that output wave is square wave and its frequency is 20kh and i m not good programmer main problem is that

jremington

Quote
i m not good programmer main problem is that
You have two options:

1. pay someone to write a program for you
2. learn to write the program.

Arduino is a fine learning platform, with plenty of simple examples to help get you started.

Robin2

The normal frequency for Arduino PWM is 490 Hz (I think). You can change that, as mentioned in Reply #5.

When you have changed to frequency you can then use analogWrite() as normal. (By the way "analogWrite()" is not a very good description of what the function does - pwmGenerate() might have been a better name.)

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

naeemawan36

You have two options:

1. pay someone to write a program for you
2. learn to write the program.

Arduino is a fine learning platform, with plenty of simple examples to help get you started.
thnz sir i m trying to learn coding and thats why i posted this here so i get help in learning

naeemawan36

The normal frequency for Arduino PWM is 490 Hz (I think). You can change that, as mentioned in Reply #5.

When you have changed to frequency you can then use analogWrite() as normal. (By the way "analogWrite()" is not a very good description of what the function does - pwmGenerate() might have been a better name.)

...R
Sir i didnt find pwmGenerate() in arduino website if u hav anylink please share and am trying to implement manually like this
void loop()
{
  digitalWrite(13, HIGH);
  delayMicroseconds(10); // Approximately 10% duty cycle @ 1KHz
  digitalWrite(13, LOW);
  delayMicroseconds(40);
}
only problem i m struck with PID OUTPUT that how that output can be converted into in range of my time period 50us if i get that above code willbe implement i hope so

Go Up