Yahoo Groups archive

AVR-Chat

Index last updated: 2026-04-28 22:41 UTC

Thread

Problem with code(simulates in AVR Studio fine, but not in real life)

Problem with code(simulates in AVR Studio fine, but not in real life)

2009-06-09 by inuyasha10121

Alright, I don't really understand why this isn't working.  I've worked with arduino before, but this is the first time i've gone into bare-bones AVRs(in this case, ATtiny2313).  I'm making a controller mod, where you hit Right-click, left-click, right-trigger to engage rapid fire right-trigger mode, and the same combination only with left-trigger to turn the turbo mode off.  So, this is how I have the pins going for the trip(NOTE: This isn't in the controller yet, i'm just using a DIP-switch and some LEDs for testing purposes).  

PORTD
I:RC	2
I:LC	3
I:RT	4
I:LT	5
PORTB
O:RT	0
O:LED	1

The left shows the function, the right shows the bit in the register.

Alright, time for the code...weeeee.

[code]
#define F_CPU 1000000UL
#include <avr/io.h> 
#include <util/delay.h>

typedef unsigned int u16;
typedef unsigned long u32;


int main(void) 
{ 
	DDRD = 0;
	PORTD = 0;
	DDRB = 0xFF;
	PORTB = 0;
	while(1)
	{
		while(bit_is_clear(PINB,1))
		{
			if(PIND == 0x1C)
			{
				PORTB |=(1<<1);
			}
			if(bit_is_set(PIND,4))
				PORTB |=(1<<0);
			else
				PORTB &=~((1<<0));
		}
		while(bit_is_set(PINB,1))
		{
			if(PIND == 0x2C)
			{
				PORTB &=~((1<<1));
			}
			if(bit_is_clear(PIND,3) && bit_is_set(PIND,4))
			{
				PORTB |=(1<<0);
				_delay_ms(100);
				PORTB &=~((1<<0));
				_delay_ms(100);
			}
			else
				PORTB &=~((1<<0));
		}
	}
	return 1;
}
[/code]

When I turn the chip on, the LEDs kinda freak out.  The LED output LED stays solid, the RT output LED pulses a bit, but it should be off because i'm not supplying voltage to any of the input pins.  Not sure what to do at this point.  Any suggestions?

Re: [AVR-Chat] Problem with code(simulates in AVR Studio fine, but not in real life)

2009-06-10 by John Samperi

At 11:25 AM 10/06/2009, you wrote:
>the LEDs kinda freak out.

Do you have the necessary pull up or pull down resistors on the switches?

Regards

John Samperi

********************************************************
Ampertronics Pty. Ltd.
11 Brokenwood Place Baulkham Hills, NSW 2153 AUSTRALIA
Tel. (02) 9674-6495       Fax (02) 9674-8745
Website  http://www.ampertronics.com.au
*Electronic Design * Custom Products * Contract Assembly
********************************************************

Re: [AVR-Chat] Problem with code(simulates in AVR Studio fine, but not in real life)

2009-06-10 by David VanHorn

On Tue, Jun 9, 2009 at 10:45 PM, John
Samperi<samperi@ampertronics.com.au> wrote:
> At 11:25 AM 10/06/2009, you wrote:
>>the LEDs kinda freak out.
>
> Do you have the necessary pull up or pull down resistors on the switches?
>
> Regards

That, and debouncing would be where I'd look.

I generally avoid doing things directly off switches, preferring to
scan them every few milliseconds, and use that.

-- 
There is no computer problem which cannot be solved by proper
application of a sufficiently large hammer.

Re: Problem with code(simulates in AVR Studio fine, but not in real life)

2009-06-10 by inuyasha10121

...*facepalm*Damn it all I forgot to put pull downs on the switches...it works fine now, lol.  Thanks for the help!  I'll post the finished product later on.

--- In AVR-Chat@yahoogroups.com, John Samperi <samperi@...> wrote:
Show quoted textHide quoted text
>
> At 11:25 AM 10/06/2009, you wrote:
> >the LEDs kinda freak out.
> 
> Do you have the necessary pull up or pull down resistors on the switches?
> 
> Regards
> 
> John Samperi
> 
> ********************************************************
> Ampertronics Pty. Ltd.
> 11 Brokenwood Place Baulkham Hills, NSW 2153 AUSTRALIA
> Tel. (02) 9674-6495       Fax (02) 9674-8745
> Website  http://www.ampertronics.com.au
> *Electronic Design * Custom Products * Contract Assembly
> ********************************************************
>

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.