Basic Circuit for ATMega8515L (help!)

Go To Last Post
15 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi,

Basic question: What's the basic circuit I need to create to run an ATMega8515?

I'm (obviously) new to this but very excited about plans to use an AVR to control a ball throwing machine I'm building. Eventually I plan to control two motors with PWM and probably a couple more stepper motors to aim the thing. I also hope to sense the PWM control motors' speed.

But, I'm stumbling with the very basics. I've got a decent programming background, but the electronics are all new. I've found David Cook's robot building books VERY helpful for motor control circuits and some basics on electronics.

I've just recently gotten an STK500 which comes with a ATMega8515L pre-programmed with a simple LED flashing program. What I wanted to do was run that same ATMega8515 on a breadboard as a small step towards building my own circuits. But I can't get it to work.

Here's what I thought would work:

5+V to Pin40 (Vcc)
Ground to Pin20 (GND)
One LED with 470ohm R between Pin1 (PB0) and ground
(in the test program PortB is output for all bits, but I'm just trying to get one to work)

Then I tried using a jumper from 5+V to touch Pins 10-16 (PD0-6) as inputs.

But that LED on PB0 isn't flashing on and off as I expected. I've tried several variations like reversing the LED (in case it was backwards) and connecting the LED on the output pin to 5+V, and other potentially dumb things.

As you can tell, I'm relying on the internal oscillator and I've left XTAL1 and XTAL2 discounnected as that's what I read in the datasheet. But I'm suspicious about that.

Any suggestions GREATLY appreciated.

Thanks,
Tim

[/url]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Try putting a 10k resistor between the Reset pin and Vcc.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
Then I tried using a jumper from 5+V to touch Pins 10-16 (PD0-6) as inputs.

You will get an incredible amount of 'bouncing' using that method. Not to mention what might happen to your +5V if PD0-6 are set up as outputs and driving a low out on those pins. There are hardware and software debouncing methods discussed here regularly. Try doing a forum search using 'debounce' as a keyword.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Search out old threads for these things:

"RESET pull-up" (or maybe "RESET circuit") on how to have a good stable circuit at the reset pin.

"Decoupling capacitors" on how to make Your circuit less noisy. (You place a small cap between VCC and GND as close as possible to the AVR to eat up the spikes that the AVR will create on these nets).

"Storage capacitor", "power supply" etc for threads on how to create a stable power supply with enough "ohhhhmp!" to defeat power surges.

For the failing LED blinker, please post Your code. (You could start by checking that You really used PIND rather than PORTD when trying to read the input - a standard mistake that at least half of us has made on first attempts).

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

SteveN wrote:
Try putting a 10k resistor between the Reset pin and Vcc.

Thanks, I tried it, but still no luck!

SteveN wrote:
You will get an incredible amount of 'bouncing' using that method.

Thanks for sensitizing me to bounce. I'll take that into account in the future, but for now I'm just trying to get the test program working to flash a LED - I just want evidence of some I/O, but don't care really if it's error-prone (please correct me if I'm wrong here)

JohanEkdahl wrote:
"Decoupling capacitors" on how to make Your circuit less noisy...

Thanks for these and other suggestions. I'm using a voltage regulator (LM2940ct-5.0) with a few capacitors for the 5+ supply. I've got nothing else in the circuit, so I hope that is sufficient.

JohanEkdahl wrote:
Search out old threads for these things:

Maybe I'm not very good at searching, but I've generally tried searching forum posts to answer my questions and found it very hard to find what I'm looking for. Is there anything online that get's you through the very basics for someone just starting out?

I'm justing the test program that comes preprogrammed on the ATMega8515 in the STK500. I think the code is

;***** STK500 LEDS and SWITCH demonstration
.include “8515def.inc”
.def Temp =r16 ; Temporary register
.def Delay =r17 ; Delay variable 1
.def Delay2 =r18 ; Delay variable 2
;***** Initialization
RESET:
ser Temp
out DDRB,Temp ; Set PORTB to output
;**** Test input/output
LOOP:
out PORTB,temp ; Update LEDS
sbis PIND,0x00 ; If (Port D, pin0 == 0)
inc Temp ; then count LEDS one down
sbis PIND,0x01 ; If (Port D, pin1 == 0)
dec Temp ; then count LEDS one up
sbis PIND,0x02 ; If (Port D, pin2 == 0)
ror Temp ; then rotate LEDS one right
sbis PIND,0x03 ; If (Port D, pin3 == 0)
rol Temp ; then rotate LEDS one left
sbis PIND,0x04 ; If (Port D, pin4 == 0)
com Temp ; then invert all LEDS
sbis PIND,0x05 ; If (Port D, pin5 == 0)
neg Temp ; then invert all LEDS and add 1
sbis PIND,0x06 ; If (Port D, pin6 == 0)
swap Temp ; then swap nibbles of LEDS
;**** Now wait a while to make LED changes visible.
DLY:
dec Delay
brne DLY
dec Delay2
brne DLY
rjmp LOOP ; Repeat loop forever

THANKS for the help.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I've tried a few more things but still no luck.

I checked out the STK500 schematics and it looked like I had voltages backwards for both the LED output and the inputs. If I'm reading that schematic right, it looks like the LED should be connected from the output pin through a resistor to 5+V. I tried it (reversing the LED), no luck!

The schematic also made it look like I should connect the input pins to ground when sending an input signal. Tried it, no luck.

The schematic also appeared to have pull-up resistors on all the inputs, so I tried that, and still no luck.

I just had a thought that perhaps the switches on the STK500 actually break the circut when pushed. Not sure that's at all likely, but I'm desperate here. So it might actually be that the input pins are pulled down until the switches are push, at which point the pins are pulled up. Maybe I'll try that (again, I'm desperate!).

I'm still struggling here. Any good ideas are very welcome!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Just a few comments.

1) The reason we usually tie the LED to VCC is because CMOS pins are usually capable of sinking more current to ground with less power being dissipated by the micro. Sourcing a LED to GND should also work. so that change is not critcal.

2) It is typical to enable the port pull up resistors and tie the input switches to gnd, but, again there is no absolute need to do this. If your switches source when pressed then pulldown resistors are needed.

I would remove the input pin stuff from your code first and get the LED to light correctly. How much of a delay is provided? I'm not familiar with your micro model but is it running at 1Mhz? and doesn't the delay routine create 1Mhz/65536 = 66mS? Is that enough.

I've heard here many time to try your code out on the AVRStudio simulator first as it will allow you to single step your code and confirm that all works as you expect. I also believe that someone here has a plug-in that adds input switches and LED outputs to the simulator.

DFR

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Isn't the 8515 that comes isntalled on the stk500 set to use an external crystal on the stk500 by default (haven't rec'd mine yet but I thought that's what the docs said).

If that were the case you need to either set the fuse bits in the 8515 to use internal before you move it to your breadboard, or supply your own external crystal on your breadboard.

edit: I did notice you mentioned you are "relying on the internal oscillator", but you didn't say if you actually set the fuse bits to internal before moving it :)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi,

The OP mentioned that he received a mega8515 with his STK500. Apparently that is what is shipping with STK500's these days (instead of AT90S8515's, which is what I received with my STK500 several years ago :-) ). The AT90S8515 only really had the option of using an external crystal/resonator/oscillator. The mega8515 has the internal RC oscillator selected by default from the factory, 1MHz I think.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

haunaben wrote:
set the fuse bits to internal before moving it :)

That sounds very helpful. Do I set those fuse bits in programming? I assume so. I'll check the datasheet

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Back to basics I'd suggest....

The STK demo program isn't that straightforward to port to an external board, so try this one that works fine on my STK500. It flashes the LED on PortB pin0 about 4 times/per second when the 8515 fuse for the internal 1MHz clock is set. EDIT: This is the default fuse setting that comes with the Mega8515 on the STK500

IMHO, you just need 5v, 0V, a decoupling capacitor close to the 8515, /RESET tied to 5v via a 10k resistor, and the LED from PortB pin 0 (leg1) to 0V (pointy end of LED symbol to 0V). When this works, you can expand it to more complex stuff...

;***** LED demonstration
.include "8515def.inc"

;***** Initialization
rjmp 	start			;Reset Handler

;main program start
start:
	
	;stack pointer initialisation
	ldi 	r16,high(RAMEND)
	out	SPH,r16
	ldi	r16,low(RAMEND)
	out	SPL,r16
	
	; Set PORTB to output
	ser r16
	out DDRB,r16 

loop:
	sbi PORTB, 0x00 ; LED on
	rcall delay
	cbi PORTB, 0x00 ; LED off
	rcall delay
	rjmp loop

;**** Wait a while to make LED changes visible.
delay:
	ldi r25, 0x80
	ldi r24, 0x00
	
delay_loop:
	sbiw   r25:r24, 1
	brne delay_loop
	ret
Last Edited: Wed. Dec 28, 2005 - 11:02 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

timwhunt wrote:
haunaben wrote:
set the fuse bits to internal before moving it :)

That sounds very helpful. Do I set those fuse bits in programming? I assume so. I'll check the datasheet

As SteveN pointed out you said it came with a mega8515 and is probably already set to internal 1mhz anyway per the mega8515 datasheet, but it's still worth double checking. Take a look at the STK500 User Guide PDF, section 5.3.2 for reading/setting the fuse bits in avr studio.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have a couple of circuits on my new website (download page) which you may be able to use as a reference for your hardware.

ps DXIO-3 and DXIO-5 both use the M8515

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hurray and thank you, thank you, thank you!!

I got it to work. Rarely has a simple blinking LED brought such joy and ended such frustration! :D

In the end it seems to have been fuse setting for internal/external oscillator that was the problem. It was set for an external oscillator, and switching to an internal oscillator got it working. Special thanks to haunaben for pointing that out.

I might not have gotten it working with out the pull-up resister on reset, so thanks for that too SteveN.

I learned some important stuff along the way from others, and really anyone who took the time to make a suggestion was really appreciated.

Best regards,
Tim

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Congratulations - onwards and upwards now.... :)