Help using microcontrollers to implement a control system

mAdD INDIAN

Diamond Member
Oct 11, 1999
7,804
1
0
Hello folks,

I'm interested in implementing a feedback control system on a microcontroller, but I have some questions.

I haven't done something like this before, as most of my microcontroller work has been done on a Motorola 68k on a propertiery development board with all the inputs/ouputs already there.

However, for the purposes of this project, we don't have those dev boards.

The project is to essentially control the height of a leviated object. The control system will be using a Hall sensor to detect the position of the object (this will be the 'feedback') and will manipulate the electromagnet accordingly to reduce variance between the expected height and the actual height.

Now for this, we need to give input to the microcontroller/control system what the expected height should be.

Initially, we are thinking of using the keyboard of a computer to be the input, but we are not sure how to tie it in to the microcontroller.

I've been researching using the Atmel AVR-series of microcontollers. They seem to be pretty decent and versatile.

the second question is, has anyone done this before? I'm unsure how to connect Hall sensors to the microcontroller, i'm assuming I'd need some circuitry in the middle to make sure the output of the Hall sensors matches the input impedance/max voltage of the microntroller. I would also think the output of the Hall sensor would have to go through the ADC of the microcontroller? Unless there are Hall sensors which give a digital output.

Sorry for the long winded post, I'm essentially asking if anyone has done something like this before and if they have any advice they would like to share.

Thanks
 

smack Down

Diamond Member
Sep 10, 2005
4,507
0
0
For input I would recommend having the user hold the object to be leviated at the requested height and then pushing a button. Record that height and use it as the set point in the control system. This will eleminate alot of potential errors. If you do need to enter the actual height then I would suggest using a host controller to deal with the keyboard input in hyperterminal. If you do go with a text input system you may need to create a look up table if your sensor are not linear.

If sensor you choose isn't designed for a micro-controller input make sure you put diodes at the input to the microcontroller to protect it from the sensor inductance or EMF effects. Same goes for the electromagnet. I would recommend using the PWM and an H bridge to control the electromagnet. You will not be able to drive the electromagnet right off the microcontroller.

Before selecting the correct the microcontoller you need to determine the frequency of the control loop. If you are going to use a real digital control system you should be a microcontroller designed for DSP work. And it would allow you to easly design a low pass filter to reduce noise.

If you are going with a very simple control system, where if the object is to close increase power and object to far decrease power then any MCU will work. The lag from the sensors will be much greater then the period to adjust the system. Some mcu, PIC18F, have a special input pin that can trigger an interrupt when the analog value on the pin is greater/less than a level set in a register.
 

bobsmith1492

Diamond Member
Feb 21, 2004
3,875
3
81
How are you setting up hall-effect sensors? They're not very accurate/have poor resolution from what I've seen. Is it going to be tied in with the electromagnet? If so, you'll probably need to test it to see how they respond and program that into the controller like smack Down said (it sounds like this is his area more so than physics! :p)

For sure, any microcontroller should be able to handle the control needed; a serial interface with the computer is super-easy, but you need a level converter for RS232 (it's NOT a 5V logic level!). I've used the AVR series for a large project, and they do work pretty well; AVR also has a free development environment online.

As far as the Hall sensors go, you'll for sure need to research them a bit more. I'm not sure they can do what you're thinking, but I'm not sure I know what you're thinking either... again, your best be would probably be to build a prototype and see if you get any useful readings. I'd always thought they were very close-range, fairly low-precision sensors.
 

ScottMac

Moderator<br>Networking<br>Elite member
Mar 19, 2001
5,471
2
0
If the levitated object is going to be something like a cylindrical slug of aluminum in a plastic tube, it might be better to use optical sensors or a *series* of Hall Effect transistors / devices.

Many of the microcontrollers include comparators so you'd be able to set up a group of "This > That" comparisons (with / without some sort of mux, depending on the required resolution and number of sensors).

For the RS232 level conversion, you'll probably end up with something like a MAX232 chip (Dallas Semiconductors) ... it'll take the TTL-level RS232 signals and upconvert them to ~10-13 volts for EIA levels.

Unless the project specifically requires assembly language, you might look around for a C or BASIC compiler to do the code. The open-source gcc compiler has variants for Atmel, Motorola, 8051 types, and some others.

Hitec has a C compiler for the PICs, and the demo version is free and can do up to ~2000 lines. I think there's at least one BASIC compiler available for free, and a t least one that's "cheap" (~US$100.00)

Zilog ( I believe) has a free IDE suite available for their microcontrollers (Acclaim! and Encore!)

NetBurner also has a free IDE for their mcu package(I think most are Coldfire / Freescale based - lots of I/O, pretty fast ... )

And , of couse, there's the "Stamps:" The OS, clock ... pretty everything you need on a 24 or 40 pin DIP. Very easy to use for development, but it's more of a system than a microcontroller ... so I'm not sure if it'd qualify. They do have a new multi-core chip out that's pretty slick. Parallax has a variety, some are faster, some program in native Java, etc.

If you want to get fancy with it, some mcus have a built-in Ethernet MAC - add a PHY and a TCP/IP stack and use telnet or a web page to control / monitor it instead of RS232. The stack and Real-Time OS (RTOS) are frequently available as examples or code snippets on the company's support site.

Sound like a hoot, let us know what you decide and how the project came out.

Good Luck

Scott



 

mAdD INDIAN

Diamond Member
Oct 11, 1999
7,804
1
0
Originally posted by: bobsmith1492
How are you setting up hall-effect sensors? They're not very accurate/have poor resolution from what I've seen. Is it going to be tied in with the electromagnet? If so, you'll probably need to test it to see how they respond and program that into the controller like smack Down said (it sounds like this is his area more so than physics! :p)
Their resolution is fine for our intended purpose. The Hall Sensors will essentially monitor the change in magnetic field that is caused by our levitating object (which will be a simple object with a magnet attached to it). If the object moves closer to the hall sensor (which will be situated by the electromagnet) the readings will change. We obviously will have to calibrate the Hall sensors readings to see how it corresponds to the object's position.

For sure, any microcontroller should be able to handle the control needed; a serial interface with the computer is super-easy, but you need a level converter for RS232 (it's NOT a 5V logic level!). I've used the AVR series for a large project, and they do work pretty well; AVR also has a free development environment online.

This is the part I am worried about. I'm not sure how to connect peripherals to the microprocessor. In the past, we always used Motorola 68k in Univeristy, and they were hooked up to this massive devleopment board (called the Gizmo board) which had USB ports, RS232 ports, ADC/DACs, etc...for us to use; and it was pretty simple connecting devices to it.

So I don't have the knowledge of how to do all that without those boards. How would I connect the Hall sensor to the microprocessor? Or a RS232 connection?

As far as the Hall sensors go, you'll for sure need to research them a bit more. I'm not sure they can do what you're thinking, but I'm not sure I know what you're thinking either... again, your best be would probably be to build a prototype and see if you get any useful readings. I'd always thought they were very close-range, fairly low-precision sensors.

Hopefully my explanation above clarifies how I intend to use the Hall sensor?

ScottMac: We plan on using the freely available C compiler for the Atmel AVR boards.

Again, thanks for all your help folks! Its greatly appreciated.
 

bobsmith1492

Diamond Member
Feb 21, 2004
3,875
3
81
Here's a schematic showing a serial interface:
http://www.kmitl.ac.th/~kswichit%20/easy1/easy1_3.pdf

As the title says, it is pretty easy. :)

Really, there is nothing special on microcontroller development boards; the one I have has a pair of 232 level converters and just a bunch of headers and solder points for all of the IO lines.

If you're sure the Hall sensors will work, go for it; I'd still say to build a test setup first. As far as interfacing them, if you got a Hall sensor that runs on 5V with a proportional analog output, you could run that directly to an A/D input line of a microcontroller. Otherwise, if they run at higher voltages, simply use a 2-resistor voltage divider to control the input voltage to a reasonable range. Also, use a 5.1V Zener diode for protection against static and/or overvoltage and whatnot (run the input line through a resistor, say 100 ohms, and tie a zener between the microcontroller pin and ground).

Hope that helps some.
 

gbuskirk

Member
Apr 1, 2002
127
0
0
This would be a fun project, with some good lessons in control system stability. I can imagine some pucks embedded in the ceiling tile. Based on a short reading, the Hall sensor will give a voltage signal proportional to its bias current, the flux density, and the (sine of the) angle between the plane of the sensor and the flux density. You may adjust the bias current to set the desired level. Modulate the electromagnet current with the voltage signal from the sensor. I'd probably have more fun without the micro.
 

blahblah99

Platinum Member
Oct 10, 2000
2,689
0
0
Originally posted by: mAdD INDIAN
Hello folks,

I'm interested in implementing a feedback control system on a microcontroller, but I have some questions.

I haven't done something like this before, as most of my microcontroller work has been done on a Motorola 68k on a propertiery development board with all the inputs/ouputs already there.

However, for the purposes of this project, we don't have those dev boards.

The project is to essentially control the height of a leviated object. The control system will be using a Hall sensor to detect the position of the object (this will be the 'feedback') and will manipulate the electromagnet accordingly to reduce variance between the expected height and the actual height.

Now for this, we need to give input to the microcontroller/control system what the expected height should be.

Initially, we are thinking of using the keyboard of a computer to be the input, but we are not sure how to tie it in to the microcontroller.

I've been researching using the Atmel AVR-series of microcontollers. They seem to be pretty decent and versatile.

the second question is, has anyone done this before? I'm unsure how to connect Hall sensors to the microcontroller, i'm assuming I'd need some circuitry in the middle to make sure the output of the Hall sensors matches the input impedance/max voltage of the microntroller. I would also think the output of the Hall sensor would have to go through the ADC of the microcontroller? Unless there are Hall sensors which give a digital output.

Sorry for the long winded post, I'm essentially asking if anyone has done something like this before and if they have any advice they would like to share.

Thanks

I've did this before... designing a controller for 2nd order unstable plant model. (1/s^2 or something like that).

I'm assuming that you already designed the controller and closed the loop and have simulated the controller to make sure it works in simulations? All this is done in the domain (s or z domain) of preference. I usually design it in the z-domain since it gives a more "visual" representation of what actually would happen if it was hardware implemented.

Once the simulations work, you have to transform it to z-domain with sampling rate factored in (if it's not in z already) and obtain the difference equation so you can implement it in software.

All the laws of feedback control apply in hardware implemention - if your sensor has a gain, then you must model the gain in the sensor, or convert it to the unity-feedback model which simplifies things a bit.

If you plan to use a hall sensor, I would hook it up to a schmidt trigger type comparator and feed it into a timer port of the MCU. Use an interrupt on the MCU to interrupt on falling/rising edge of the timer port. The interrupt routine would need read out the counter ticks and convert to actual time, and finally convert to rads/s. Take the derivative of it to obtain angular acceleration for use in your controller if it requires it.

You dont' need a fancy MCU to do this, only one that has enough memory to store and process data, a timer port, and a way to convert the digital output of the controller to analog, which can be done with a PWM port on the MCU whose output is filtered by a passive RC network. For high bandwidth plants or for more accurate analog output, you can use a seperate DAC.