Arduino to ATTin85 -- Assembly is evil! (my first post!)

Stuck with a problem in your code? Seek help here.

Arduino to ATTin85 -- Assembly is evil! (my first post!)

Postby ariccio » October 22nd, 2012, 12:13 am

I've been working on a nutrition countdown clock - 3 IV9s, and an M5450 to drive them.

The clock displays the number of days until the event, and every 5 seconds it switches to display "P.I." for a second. I'm using a rotary encoder to change the displayed number, and turn the clock on/off.

I have a video of it on youtube:
http://www.youtube.com/watch?v=QutpK5NM0co

I transferred it to an Adafruit Perma-Proto, and wired it up (I'm quite proud of my wiring)

Image
((the hell is with the massive size?? :oops: ))

However, I cannot get my code to work with the ATTiny85!! When I upload my code to it -important pins swapped to their ATTiny counterparts - and drop it in the IC socket (that I thankfully included), the clock simply does not work! All 24 segments light up, only flickering when I turn the encoder or tap the on/off button.

It SEEMS to be due to some very obscure and nonsensical differences in the naming of ATTiny V ATMega register naming. You can see some of the hacks I attempted in the included modified libraries, all succeeded in reducing compiler warnings, but not the actual functionality I'm looking for!

Some of the hacks include
Code: Select all
#ifndef NO_PORTB_PINCHANGES
#ifndef ATTINY85
PCintPort portB=PCintPort(2, 0,PCMSK0); // port PB==2  (from Arduino.h, Arduino version 1.0)
#endif
#endif

#ifdef ATTINY85
PCintPort portB=PCintPort(2, 0,PCMSK); // port PB==2  (from Arduino.h, Arduino version 1.0)
#endif

Where the difference is that the ATTiny register is, and MUST be referred to as PCMSK (ie PinChangeMask) and not PCMSK0 :evil:

Code: Select all
#ifndef ATTINY85
   PCICR |= PCICRbit;
   #endif
   #ifdef ATTINY85
   GIMSK |= PCIE;
   #endif

Is another example, wherein PCICR & PCICRbit (ie PinChangeInterruptControlRegister) on the ATMega, is GIMSK (General Interrupt Mask Register) & PCIE (Pin Change Interrupt Enable) on the ATTiny :? :? :? :(

And lastly,

Code: Select all
#ifndef DISABLE_PCINT_MULTI_SERVICE
   #ifndef ATTINY85
      pcifr = PCIFR & PCICRbit;
      PCIFR = pcifr;   // clear the interrupt if we will process it (no effect if bit is zero)
   } while(pcifr);
   #endif
   #endif
   #ifdef ATTINY85
      pcifr = PCIF & PCICRbit;
      GIFR = (1<<PCIF);   // clear the interrupt if we will process it (no effect if bit is zero)
   } while(pcifr);
   #endif

Where we're dealing with some General Interrupt Flag Register weirdness :evil: :(


I'd really appreciate some help!!

And by the way
Ignore the dirty dirty dirty hack that is
Code: Select all
extern volatile float nomone;

:D
User avatar
ariccio
 
Posts: 8
Joined: October 11th, 2012, 10:05 am
Location: NYC

Re: Arduino to ATTin85 -- Assembly is evil! (my first post!

Postby semicolo » October 22nd, 2012, 7:01 am

Maybe the fuses that set the clock speed/source?
User avatar
semicolo
 
Posts: 269
Joined: December 13th, 2011, 3:32 pm

Re: Arduino to ATTin85 -- Assembly is evil! (my first post!

Postby GaspingSpark » October 22nd, 2012, 11:19 am

In addition to being too large, that photo has your GPS coordinates embedded in it. You might want to strip those out next time. :)
GaspingSpark
 
Posts: 180
Joined: March 8th, 2011, 10:24 am

Re: Arduino to ATTin85 -- Assembly is evil! (my first post!

Postby ariccio » October 22nd, 2012, 8:24 pm

semicolo wrote:Maybe the fuses that set the clock speed/source?


Hmmmmmmm I like the thinking, but I have a gut feeling it's interrupt related.

GaspingSpark wrote:In addition to being too large, that photo has your GPS coordinates embedded in it. You might want to strip those out next time.

:D
User avatar
ariccio
 
Posts: 8
Joined: October 11th, 2012, 10:05 am
Location: NYC

Re: Arduino to ATTin85 -- Assembly is evil! (my first post!

Postby ariccio » October 23rd, 2012, 7:35 pm

If it is interrupt related (i.e. too few interrupts actually available on the ATTiny - would it make sense to:
Code: Select all
Store the default/last state of input pins in a bool array/a bitmask;
Split everything that generates an interrupt, and wire to a single pin interrupt (think like an OR gate):
                      Attached to an ISR that iterates over a bool array/a bitmask
                      Compares that array/mask [i]with[/i] the current state of the pins
                      Calls a function that is mapped(previously to an interrupt) to that pin
                      Stores the state of that pin
                      debounces


Even better is there a library (like pinchangeint, but with less hacking needed to port to attiny85) to handle the tedious business?

OR is it something simple like forgetting to turn off interrupts during a routine?
User avatar
ariccio
 
Posts: 8
Joined: October 11th, 2012, 10:05 am
Location: NYC

Re: Arduino to ATTin85 -- Assembly is evil! (my first post!

Postby ariccio » October 30th, 2012, 7:01 pm

Aha! I made some advances.

I noticed that by shifting a 1 into PCIF I was putting it into an infinite interrupt loop - shifting zero clears it.
Code: Select all
#ifdef ATTINY85
      pcifr = PCIF & PCICRbit;
      GIFR = (1<<PCIF);   // clear the interrupt if we will process it (no effect if bit is zero)
   } while(pcifr);
   #endif


I also added sei() here

Code: Select all
                        // Link the previous' next to the found next. Then remove the found.
         if (prev != NULL) prev->next=current->next; // linked list skips over current.
         else firstPin=current->next; // at the first pin; save the new first pin
         delete current;
         SREG = oldSREG; // Restore register; reenables interrupts
         sei();
         return;


So it's almost fully working - it alternates between "p.i."/the number of days, and upon turning the encoder it will immediately switch from "p.i." to the number of days.

http://www.youtube.com/watch?v=gXk72KRiwX4
However the only remaining problems are

    A) Turning the encoder doesn't actually change the number of days (!)
    &
    B) Clicking the encoder doesn't turn it on/off

I can't figure out why the code for interrupter "P.I." (changing to days) works, but the code to change the number of days doesn't! Maybe it has something to do with the fact that it's stuck on 255? Isn't that the default value for uninitialized memory?

Any advice is appreciated!
Thanks again.
User avatar
ariccio
 
Posts: 8
Joined: October 11th, 2012, 10:05 am
Location: NYC

Re: Arduino to ATTin85 -- Assembly is evil! (my first post!

Postby ariccio » November 17th, 2012, 7:42 pm

This is becoming a project log.....

Well I figured out where the last problem was. I was trying to use the reset pin as I/O without first setting the fuse! So it'd reset when the encoder was turned.

#dumbmistakes

Now I just have to figure out how to properly set up I/O on the reset pin - it was definitely not intended to be used this way!
User avatar
ariccio
 
Posts: 8
Joined: October 11th, 2012, 10:05 am
Location: NYC


Return to Help Me! Software

Who is online

Users browsing this forum: No registered users and 2 guests