Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Using ADC on Atmega32, plus help and how-to.

Status
Not open for further replies.

potoole64

New Member
I have a DevBoard-M32 microcontroller kit (from Wright Hobbies) that uses an Atmega32 microcontroller chip. The kit included a disc with Bascom-AVR demo, which I have downloaded onto my PC. The small manual that I have gives a quick instruction on useing Bascom-AVR for one short program: A simple demonstration program to cause an LED to wink on and off.

Question 1) Can I do more than that with the demo?
2) Where can I find information on how to use the ADC channels on the Atmega32, (an ADC programming example)?

Thank you,
Patrick
 
Your Dev board is a very simple one contains only two 78L05s and the Mega32, not even a crystal. It works using the internal oscillator of the Mega32.

All 32 port pins are brought out and available to user and you can do whatever you want with them, if you know how to.

You need to tell us why you have bought the board (e.g. for a project, self learning or ....) so that we can offer our advice better. Do you have lots of time in this respect or are you working against a deadline?

You also need a hardware programmer to send the compiled code from PC into the M32 board. Have you bought such programmer, or else you can't change or reprogram the M32?

On the website of the supplier there is a section with examples and one of them is on ADC, with Bascom coding. Check here:

Examples on ADC and others
 
potoole64 reply

I'm an old retired guy, learning how to use microcontrollers for self interest and as a hobby. I've got the Bascom-AVR loaded on my PC and have also connected the Devboard-m32 to the computer. I've mamnaged to get a short test program to work, one which causes an LED to wink once per second, and I was darn proud of myself.:)

I found this program on a site (Wright Hobbies) that was suggested by Mr. Chung; its for an Atmega8. Will this program work with my Atmega32? Just to get me started?

Reading the value of a Pot connected to a Mega8
'Example of reading a Pot using a Mega8L mcu
'Refer to Wright Hobbies Robotics for more information​
Config Adc = Single , Prescaler = Auto 'Configure the ADC subsystem
Start Adc 'Fire up the ADC
Dim Pot As Word , Channel As Byte 'Define Variables

Channel = 0 'Set the channel we will sample
Do
Pot = Getadc(channel)
'Poll the ADC channel and assign the value to Pot
Print "ADC (" ; Channel ; ") = " ; Pot 'Print the value, Print sends the data to the serial port
Wait 1 'Wait one second
Loop
End[/
LEFT]

Thanks for the info,
Patrick​
 
I can't dish out anything specific but I recall the datasheet being incredibly helpful in describing how to configure things. But, of course, you kind of have to know what you're looking for. If you want I can post some code I used on an ATmega168 which may or may not be what you need... it may give you an idea.

Michael
 
I use atmel controllers exclusively, prominently the ATMEGA8... the mega32 ADC works a little differently than the MEGA8.
When I develop microcontroller code, the very first thing I do is to flash an LED!!! It doesn't just make you feel damn proud, it lets you know the system is working. Now, on a kit board, that may not be a big deal. But on a new design, it lets you know everything is hooked up and powered up correctly. Once you know your system works, you can get on to bigger and better things. No need stratching your head over why you can't read the ADC when you don't even have the micro powered up correctly.
I also program exclusively in asm code. Not that C doesn't have it's advantages, but ASM is where it's at, man!
I once built an RF interface, and had the serial ports configured wrong, but since the transmitter and receiver both had the same setup code, who's to say it was wrong??? I only noticed it when I tried to send data to a PC terminal. I was using the wrong (wrong for windows) edge to clock data. Also, if you want to protect your data on a closed system (you control both ends), you can use non standard bit rates (say 5000 baud vs 4800) and clock unusual edges (yeah, that's what I was doing) and of course encrypt your data. Of course, on a RF link, the FCC has rules about data encryption and all.

So, I don't know how much help to you my code will be, but for using the ADC here are some basics:
setup ADC for 8 bit, 10 bit right or 10 bit left justified (has to do with the odd 2 bits ... are they MSD or LSD, most significant digits or least significant digits). ADC ref source = external, internal 2.56V, or vcc/2. ADC clock source/scale. ADC channel (multiplexer channel, actually). Note that there are 8 external (dip) or 10 external (SMD) channels, but a multiplexer channel selection of (0-31) for single ended inputs or differential inputs. The upper selections include ground (so you can check for offset) and an internal 1.22V bandgap reference (so you can check your conversions against your selected reference). The MEGA8 only has a mux of 16 selections, and cannot do differential. So your mux selection code will be different. You also need to program single conversion mode or continous conversion mode, and interrupt mode (on or off). Once set up, you start the conversion, and wait for the end of conversion bit to set or the ADC interrupt.
 
Status
Not open for further replies.

Latest threads

Back
Top