0
\$\begingroup\$

I am working on Motor speed and position control. The requirements of the project are: 1. Set a speed to run the motor at a particular frequency. 2. Use a potentiometer to set the speed displayed on the LCD (POT and LCD on development board) 3. Create PWM signals to run the motor. Keep PWM independent of the microcontroller. 4. Use encoder to detect motor speed.

I have all the electronics sorted out and tested but my supervisor wants me to use the POT and the LCD on the development board to set a motor speed and then use that to power up a 555 Timer that I'm using to generate PWM signals as the PWM is supposed to be generated externally and not through the microcontroller. ADC converts the POT to a certain value (0 - 255).

My question is if I need the motor to rotate at 500Hz, how do I get the associated ADC value from the development board to run the 555 Timer. I need to set a value of motor speed and start the program to run the timer to oscillate at a particular frequency?

\$\endgroup\$
  • \$\begingroup\$ I can't believe how schools tend to overcomplicate things... \$\endgroup\$ – Dzarda Jan 19 '14 at 21:16
  • \$\begingroup\$ @Dzarda, Tell me about it. Is there a way how I can do that? Can I use encoders to rotate the motor at a specified speed? \$\endgroup\$ – David Norman Jan 19 '14 at 21:17
  • \$\begingroup\$ It sounds like they want you to implement a closed-loop control system, but you've not provided enough information to be sure. In that case, the setpoint (500Hz) would be compared with the actual motor speed (from the encoder) to give an error signal, which would go through a control algorithm to somehow change the PWM. Does the dev board have a DAC? \$\endgroup\$ – Spehro Pefhany Jan 19 '14 at 21:33
  • \$\begingroup\$ @SpehroPefhany, Yes the Dev board does have a DAC. I was thinking of using a DAC but would it not require the microcontroller to constantly poll the DAC? And yes you are right that is exactly what the project is \$\endgroup\$ – David Norman Jan 19 '14 at 21:35
  • 1
    \$\begingroup\$ You only need to write the DAC when the pot changes position \$\endgroup\$ – Andy aka Jan 19 '14 at 22:25
1
\$\begingroup\$

It appears they want you to implement a closed-loop digital speed control. This will be an interesting project. Consider the simple block diagram below:

enter image description here

This is about as simple as you can get, in that the control algorithm is just a multiplication factor.

In your case, the "Command" is a fixed number (500Hz). The Tachometer will feed back a pulse rate that depends on motor speed (500Hz when it is at the right speed). You can use the microcontroller to measure the frequency coming from the tachometer. There are a number of ways to do that, the main system-level requirement is that the measurements have to be fairly frequent (in relation to how long the motor takes to spool up).. for simplicity, suppose you count pulses for 0.2 seconds, and multiply by 5.

Following the block diagram, subtract the tachometer reading from the command. You'll have an error, which you can then multiply by the \$K_p\$ factor. Let's suppose your DAC output needs to be 1.67V for 0% PWM and 3.33V for 100% PWM. Further, let's make a guess that 50% PWM is about right. And let's say a +/-2.5% error is acceptable, so we'll be happy with a gain of 20. We'll need a factor of \$1.67\over{500}\$ to normalize the input and output gains, and a bias of 2.50V. So, our output voltage to the motor driver PWM will be \$V_{out}\$ = \$ error\cdot K_p\over{500} \$\$\cdot 1.67V\$ + \$2.50V\$. The voltage also needs to be limited to no less than 1.67 and no more than 3.33V. Thus, the PWM will be 0 or 100% at an error of +/-12.5 RPM (+/-2.5% of setpoint).

The dynamics of this system (stability, response to disturbances like torque changes, and overshoot) may not be acceptable, and perhaps some integral factor is required in the control algorithm, but the overall structure should be similar to this.

\$\endgroup\$
  • \$\begingroup\$ Thanks for this Spehro. Also, I was wondering how to go about Digital to analog conversion. Would I need to poll the DAC to update its value in a while loop? Or can I just do it once and the DAC value stays constant at that level. I am asking this because I have no idea how to program DAC. I know ADC needs frequent sampling which would keep the microcontroller occupied. Does DAC need frequent sampling too? \$\endgroup\$ – David Norman Jan 19 '14 at 22:54
  • \$\begingroup\$ In the example I gave, you had periodically available tachometer results (every 200msec). So you can calculate and output the new PWM command every 200msec. In general for control loops you want a constant periodic update, as you'll see when you get to more sophisticated controllers.. the \$T_s\$ sample time figures into almost every equation. \$\endgroup\$ – Spehro Pefhany Jan 19 '14 at 22:57
  • \$\begingroup\$ The PWM signal comes from the 555 Timer. All I have to do is to output an analog voltage to pin 7 (discharge) of the timer to generate that signal. Now, the Analog voltage comes from DAC output pin of C8051F020 micro present on the Dev board. My Question is do I need to poll DAC to maintain its output voltage or can I just do the calculation ones and be done with it? \$\endgroup\$ – David Norman Jan 19 '14 at 23:05
  • \$\begingroup\$ I think you need to update it regularly, as the control output. By the way, it's not called "polling", that's when you're checking status regularly or something like that. A DAC typically behaves as a zero-order hold. en.wikipedia.org/wiki/Zero_Order_Hold \$\endgroup\$ – Spehro Pefhany Jan 19 '14 at 23:09
  • \$\begingroup\$ Thanks Spehro. By polling I mean a while(1){} loop. A DAC is operated as charging and discharging of a Capacitor I think. So If I update the value of the DAC every say 200mS Wouldn't that be a problem in terms of the output going to low as soon as the internal capacitor discharges. I dont know how to explain it \$\endgroup\$ – David Norman Jan 19 '14 at 23:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.