Posted: Tue May 20, 2014 2:10 pm Post subject: ATmega328 opamp code
Hello people,
Microcontrollers are very new to me.
I'm currently following the series of articles in Elektor called "Microcontroller Bootcamp" so I'm using an Arduino Uno board with ATmega328 chip.
Elektor has chosen Bascom AVR as programming language instead of the Arduino IDE.
This is completely in line with my objective as I would like to learn to use and program microcontrollers and not only Arduino.
For the time being I can make a LED blink and use a digital input to control a digital output )
Great, but I'm a bit stuck now waiting for the third article...
One of the practical applications that I could imagine and for which I would like to use the Arduino/Bascom, makes use of opamps when it were built with classic components.
Is there a way to program the ATmega so it behaves like an opamp or a comparator?
As I'm totally new I can only imagine: two inputs being converted to digital (ADC) and then subtracted mathematically (in binary) and the result converted back to analog (DAC).
Perhaps there is another way to achieve this.
Can you show me the way to some example of code doing this?
Or do you have any other comment in this regard?
Thank you very much,
Jean _________________ The amateur is a fool. Ignorant that something is impossible, he will succeed realizing it.
Paul Godley 2ZE
most AVR chips already have an analog comparator. but the output is not routed to a pin. you can only check a bit in a register to see the output which is digital 0 or 1. So you can not use it as a normal OPAMP.
If you want to make an opamp you would need an D/A converter. some chips have both a/d and d/a but with a resistor network you can also create a D/A converter. then you can make a digital amplifier.
Maybe there are users that have a similar interest and can share some samples and ideas. _________________ Mark
Thank you for your reply.
I noticed the Analog Comparator chapter 22 in the datasheet but could not interpret its meaning.
Also it is clear that there is no D/A converter chapter.
Is it correct that to make a D/A converter with a resistor network one will need to use as many digital outputs as D/A bits?
This would use up a lot of the chips hardware...
Best regards,
Jean _________________ The amateur is a fool. Ignorant that something is impossible, he will succeed realizing it.
Paul Godley 2ZE
yes for 8 bit resolution you need 8 bits of a port. but you can also add D/A using an external chip.
Or choose a chip that has D/A as well.
analog comp : you need to enable it : ACSR.7=1 'enable
now all you need to do is watch bit 5
do
if acsr.5=0 then
else
end if
loop
it only compare voltage on ain0 and ain1 pins of the micro. and sets bit 5 according to the voltage. so usage as opamp is limited. _________________ Mark
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You cannot download files in this forum