Help getting started on programmable microcontrollers?

Hello folks,

I'm working on a project where I need a circuit that reads in a voltage, and then outputs a voltage based both on the signal, and also the past history of the signal. Sort of like PID, except that it is open loop, and the Vin to Vout function can be arbitrary and programmable. Ideally, I would like the system to be self contained, needing a computer or laptop to reprogram the algorithms if necessary. It only needs to run up to about 1 kHz.

My knowledge is as follows: I know analog electronics OK, and can build op amp circuits and a few transistor circuits. I also know Labview real time, which can pretty much do exactly what I want, but is overkill in money and also requires a computer to be there all of the time.

I have a big gap in this middle area involving digital stuff, so I would appreciate suggestions on where to start. Ideally, I would like the cost to be low and the learning time to be not too long. I know it needs some kind of ADC and DAC.

For example, here are two scenarios that I am capable of, both of which are suboptimal:

1) I can build an entirely analog circuit, with a bunch of knobs to adjust various parameters, but that's too much of a PITA, and isn't very flexible. 2) On the other end, I can throw together a cheapo DAQ card and the smallest computer possible, and install labview real time target on it, as shown here:

formatting link

This is close to what I want, but was wondering if there was anything cheaper or simpler.

Thanks

Reply to
acfang
Loading thread data ...

On a sunny day (Sat, 28 Mar 2009 01:59:10 -0700 (PDT)) it happened snipped-for-privacy@yahoo.com wrote in :

This can be done with a micro controller, for example a PIC with analog inputs. The analog output can be made by using PWM and a low pass RC filter. Could be programmable in asm, or C, or even BASIC. Not much digital hardware there.

Reply to
Jan Panteltje

[snip...snip...]

Consider the one of the Arduino boards. It's an open source hardware and software platform so the cost of entry is relatively low. On the other hand, the boards don't have an onboard DAC, just PWM. On the other, other hand, an onboard 3.3 V DAC may not do you much good, anyway. The boards have UARTs, SPI, and I2C-compatible comms, so a 1 KHz update rate to an external DAC and analog board would be quite possible.

formatting link

Otherwise, jump over to

formatting link
or
formatting link
and look at what dev boards they have available that strike your fancy. Several do have onboard DACs that could be tied into analog gain stages. Most will require separate compilers, some have bootloaders, others require dedicated programmers.

--
Rich Webb     Norfolk, VA
Reply to
Rich Webb

1kHz is actually pretty fast for a small microcontroller to do much in the way of general-purpose calculation. PID ends up being just a few simple (addition and multiplication ONLY) operations per sample the way it is usually implemented, even when you hang algorithmic barnacles off of it to make it behave reasonably at start-up etc.

For example, if your arbitrary function could include transcendental functions, you would not be able to use MOST of the microcontrollers out there at 1kHz ( most would be able to do the calculations-- though perhaps only at 10Hz-100Hz).

You might want to look into something like a DSP (but at board level or higher, given your background) if you need to have the ability to implement sophisticated algorithms at high speed. You should also consider the ADC and DAC requirements. 10 or 12 bits is a LOT easier than trying to use 24-bit ADCs/DACs and getting anything like that number of effective bits.

It might not be a clear cut choice between your default digital scenario and using a DSP.

OTOH, if you just need a 10-12 bit resolution, less accuracy, and can live with slower and/or simpler calculations, there are one and two chip solutions possible.

Best regards, Spehro Pefhany

--
"it\'s the network..."                          "The Journey is the reward"
speff@interlog.com             Info for manufacturers: http://www.trexon.com
Embedded software/hardware/analog  Info for designers:  http://www.speff.com
Reply to
Spehro Pefhany

I am doing something similar to this. I need an output proportional to the integral of the input, using a pre-generated jump table. For 8 bit accuracy, the jump table takes up only 2K of a 16K ROM. I can still generated 6 other arbitary functions on the chip.

I am thinking about storing the lookup table in serial EEPROM, to be loaded at boot.

I am doing it for under $2.

Reply to
linnix

Some of the dsPIC33 chips have built-in sigma-delta DACs.

For the 8-bit chips, it's either PWM or an external R-2R ladder.

Reply to
Nobody

If you use the development board for the SiLabs F120 or the like, you will have a multiple input ADC a couple of DACs and a fair amount of CPU power to play with.

The ADC and DAC are just connected as special function registers so programming it is fairly simple. The 8051 core is easy to write for.

Reply to
MooseFET

Thanks for the replies, everybody.

So far, it looks like my first choice would be an Arduino board using the ATmega328. The main reason being that a "kit" with USB input is pretty cheap at $30. Also, the software is free and open source, so there seem to be a lot of people using it. However, I need to be sure that it can do what I want. Here's what I am imagining in more detail:

Input: samples 2 or 4 channels at 500Hz or 1kHz, 10 bit resolution is fine, but slightly higher is preferred. Processing: Instead of it computing complicated functions, I'd upload some kind of lookup table for Vin and Vout. Maybe use interpolation? I would also add some other contributions to the result, like some value based on its past history, and maybe based on the other channels. Take some kind of derivative if possible. Output: to 2 or 4 channels at 500Hz, 8 bits is fine, but higher is preferred. I saw that you can use the I2C protocol and hang DAC's off of the board.

Anyway, I just need to know if this microprocessor can carry out these computations at 500 Hz, and if not, I'd have to move to a more powerful chip, like the 0851F120.

Thanks again

Reply to
acfang

the avrs get close to one instruction ber clock cycle and from your description of the task that sounds like plenty.

I did 4 channel DDS at ~10khz sample rate on a smaller AVR running at 10Mhz.

Reply to
Jasen Betts

For a first level approximation:

The Arduinos all seem to run at 16 MHz on a 5V board. The ATMega328's A/D peripheral needs a clock that's between 50 and 200 KHz. With the available clock prescalers, that results in an AD clock of 125 KHz.

The AD cycle time, exclusive of interrupt handling overhead, is 13 AD clock cycles, or 104 usecs, or about 9.6 KHz. There are 1664 main clock instruction cycles in this time that are available for computation, general I/O, interrupt handling, and for reading, storing, and then restarting the AD conversion process.

Reading four AD channels gives about a 2.4 KHz sample rate per channel, again neglecting other overhead.

You'll have to run the equivalent numbers for the I2C DAC you select. I suspect that an SPI DAC will permit achieving a higher output rate.

--
Rich Webb     Norfolk, VA
Reply to
Rich Webb

I did a test on the Arduino ADC where I read 100 samples into an array and did a timestamp before and after. I got a sample rate of just over

8KHz for the set. That will give you a feel for the overhead in addition to the the 9.6KHz conversion rate above.
Reply to
Dennis

Thanks everybody. I ended up ordering an Arduino

Reply to
acfang

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.