ATTINY12 - FLOATING OUTPUTS (noob question)?!?!?!?

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

Microcontroller: Attiny12
Goal: Want to blink two LEDs
Issue #1: Output pins aren't working (seem to be floating)....FIXED
Issue #2: LEDs won't blink (on 100% of time)
Programmer: AVRisp MkII
Compiler: GCC/Win-AVR
IDE: AVR Studio 4, Version 4.15

Updated Feb 9, 2009:
I hooked LEDs up to PORTB3 and PORTB4, and they won't blink like they should. The LEDs are on 100% of the time.

I've successfully used this code on an ATmega32. Why won't it work for an Attiny12?

Here's my code:

#include       
#include    
 
int main(void)
{
   int refreshRate = 1000;

   DDRB = 0b11111111;
  
   PORTB = 0b00000000; //Just initializes PORTB output logical zero

  while(1)       //This is a forever while loop
  {
     PORTB = 0b00001000;
	 _delay_ms(refreshRate);

     PORTB = 0b00010000;
	 _delay_ms(refreshRate); 

  }
  return 1;
}

Any suggestions? Thanks in advance!!!

Last Edited: Mon. Feb 9, 2009 - 11:41 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Any ideas?

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

Outputs cannot "float". They are either high or low unless the load draws a LOT of current. Then, it won't be so high or low as it ought to be.

If it is genuinely floating, it must be set as an input.

I don't know that chip, but look for alternate functions for those pins.

By the way, while Studio may be your IDE, since this is c, it must be gcc/WinAvr.

Jim

 

Until Black Lives Matter, we do not have "All Lives Matter"!

 

 

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

I'm not a GCC/WinAVR user, but I thought you had to define your processor clock rate before you could use the delay function. No?

Chuck Baird

"I wish I were dumber so I could be more certain about my opinions. It looks fun." -- Scott Adams

http://www.cbaird.org

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

Hi,

About _delay_ms , _delay_us from avr-libc:

Quote:
In order for these functions to work as intended, compiler optimizations must be enabled, and the delay time must be an expression that is a known constant at compile-time.

Try

_delay_ms(1000); 

insted of

_delay_ms(refreshRate);
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

But now I have realised you use Attiny12.
It has no RAM, so it cannot work.
You should have got folowing error after compile:

Quote:
../test.c:1: error: MCU 'attiny12' supported for assembler only

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

Visiovian: one of my settings was incorrect in AVR Studo 4. Apparently you have to declare that the chip is an Attiny12 in two different places within AVR Studio to make it work. Once I set it up properly, I was given the error message that you mentioned above. Apparently you cannot use AVR-GCC with Attiny12 microcontrollers. Good call!!!

Zbaird: I defined my processor clock rate in one of the configuration menus built into AVR Studio. I'm running it at 1.2Mhz. Good suggestion though!

ka7ehk: Thanks for the info. The pins were floating because the configurations settings were wrong as described above.

Unfortunately I don't know assembly language...I only know C code. But, I'm going to start reading up on it. Does anyone have an assembly code snippet that would simply blink an LED?

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

Why don't you use a timer for your delay instead of the software delay function _delay_mS() ?

Edit:
I don't know how C will create a stack though.

Imagecraft has a compiler for the older Tiny series processors without RAM (free I believe). If you are set on C for the TINY12, you may want to check it out.

Edit:
The product name for the older Tiny series from Imagecraft is "ICCTiny". There is a code size limited version that is free for non-commercial use.
http://www.imagecraft.com/

From now on, I would recommend one of the newer ATTINY processors (ATTINY13, 25, etc) so you have more choices in compilers.

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

Quote:
Does anyone have an assembly code snippet that would simply blink an LED?
Here is an example for tiny11. It will work with tiny12 as well.
http://www.bhargavaz.com/tiny11prg/avr-led.html
The delay loop was created with
http://www.scienceprog.com/old-good-avr-delay-loop-generator-program/

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

your code isn't right if you want them to blink. try this:

int main(void)
{
DDRB |= (1 << PB3)|(1 << PB4);
PORTB &= ~(1 << PB3)|(1 << PB4);
while (1)
{
PORTB ^= (1 << PB3);
_delay_ms(1000);
PORTB ^= (1 << PB4);
_delay_ms(1000);
}
}

edit: sorry, your code looks like it should work

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

Thanks for the great feedback! I'm going to practice some assembly coding this weekend with the links supplied by Visovian.