0

Current Mac AVR Strategy? x Game of Life
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Current Mac AVR Strategy? x Game of Life

by CaseyScalf on Fri Jun 24, 2016 4:16 am

I have purchased the USBtinyISP AVR Programmer and intend to use it on some more of your Game of Life kits.

https://www.adafruit.com/product/46 (USBtinyISP AVR)
https://www.adafruit.com/product/89 (Conway's Game of Life Kit)

After reading the tutorial I was curious if the published material from a few years ago is still the best strategy for programming an AVR chip, such as in this project, over the wire?

If so, awesome, time to carry on with the terminal!

Else, looking to explore possibly simpler ways such as this project, perhaps: https://www.obdev.at/products/crosspack/index.html

Thank you,

CaseyScalf
 
Posts: 127
Joined: Wed Nov 05, 2014 3:07 am

Re: Current Mac AVR Strategy? x Game of Life

by adafruit_support_rick on Mon Jun 27, 2016 10:48 am

Even if you get crosspack, you will still be using avrdude for programming the chip. If you want to install Arduino as well, then I recommend against crosspack, as the version of avrdude.conf that it installs tends to conflict with the version installed by Arduino.

adafruit_support_rick
 
Posts: 35095
Joined: Tue Mar 15, 2011 11:42 am
Location: Buffalo, NY

Re: Current Mac AVR Strategy? x Game of Life

by CaseyScalf on Mon Jun 27, 2016 10:51 am

Great tips,

All of those subtle details really can compound and I appreciate the advice against the new route, and to reaffirm the older tutorial.

I will endeavor the installation and let you know when I get some LEDs blinking!

CaseyScalf
 
Posts: 127
Joined: Wed Nov 05, 2014 3:07 am

Re: Current Mac AVR Strategy? x Game of Life

by CaseyScalf on Sat Jul 02, 2016 10:17 pm

Is there anyway I could just use an Arduino to upload the code?

As in drop in the IC from the Game of Life kit and upload it via the IDE?

If so, how would I structure the code for the project to be used in the IDE? Is this even possible?
https://github.com/adafruit/Conways-Gam ... r/firmware

I was thinking that although it would only wok on chips that were compatible it may ease the tech of the project.

Cheers,

CaseyScalf
 
Posts: 127
Joined: Wed Nov 05, 2014 3:07 am

Re: Current Mac AVR Strategy? x Game of Life

by adafruit_support_rick on Sun Jul 03, 2016 2:55 pm

Wellll... You certainly could port the code to an Arduino sketch. I think. For instance, the function main maps into both setup and loop:

Code: Select all | TOGGLE FULL SIZE
int main()
{
/*********************************************/
/* goes outside of setup()                      */
  uint32_t a;
/*********************************************/
/*********************************************/
/*  goes in setup()                                  */
  init();
  if ( !(PINC & _BV(5)) ) {
    compatmode = 1;
  }
  set_random();
 
  if (compatmode)
    commtimeout = 40000;
  else
    commtimeout = 60000;
/*********************************************/
  while(1) {  //delete
/*********************************************/
/* goes in loop()                                     */
    while (mode == SLEEP) {
      colony = 0xFFFF;
      display();

      SMCR = _BV(SM1) | _BV(SE); // enable sleep
      sleep_cpu();
      _delay_ms(100);
    }
    mode = AWAKE;
    SMCR = 0;  // disable sleep
    reset_border();
    for (a=0;a<commtimeout;a++) {
      if (inprogress())
   break;
    }
    transmit(3,&fetch_trans_data);
    while (inprogress()) {}

    lastcolony = colony;
    evolve();

    if (!compatmode) {
      if (colony == 0xFFFF) {
   deadcount++;
      } else {
   deadcount = 0;
      }
      if (colony == lastcolony) {
   staticcount++;
      } else {
   staticcount = 0;
      }
     
      if ((deadcount == RESPAWN) || (staticcount == RESPAWN*2) && !compatmode) {
   staticcount = deadcount = 0;
   set_random();
      }
    }
  }
/*********************************************/
  return 0; //delete
}


The rest of the code doesn't change much, I don't think. There may some functions you'll have to change to the Arduino equivalent.

adafruit_support_rick
 
Posts: 35095
Joined: Tue Mar 15, 2011 11:42 am
Location: Buffalo, NY

Re: Current Mac AVR Strategy? x Game of Life

by CaseyScalf on Tue Jul 05, 2016 5:29 pm

Hi Rick,

Thank you so much for the head start.

I am going to look a bit more into the code and see how I can properly decipher and translate it.

I think this would be a nice approach for this project. I will be sure to report back on what I find out!

CaseyScalf
 
Posts: 127
Joined: Wed Nov 05, 2014 3:07 am

Re: Current Mac AVR Strategy? x Game of Life

by steven_conaway on Sun Dec 25, 2016 1:51 am

If you ever get the code, can you please post it? I would like to use an arduino.

steven_conaway
 
Posts: 36
Joined: Fri May 20, 2016 9:18 pm

Re: Current Mac AVR Strategy? x Game of Life

by CaseyScalf on Sat Mar 09, 2019 10:52 pm

Finally getting back to this project.

How does one actually upload the code? I have the USBTiny Programmer. The blank chips. The 6 pin plugged in. AVR Dude is installed.

Is there a tutorial for this?

Cheers,

CaseyScalf
 
Posts: 127
Joined: Wed Nov 05, 2014 3:07 am

Re: Current Mac AVR Strategy? x Game of Life

by CaseyScalf on Sat Mar 09, 2019 11:17 pm

Alright, I was able to get it to work.

I used this line:

avrdude -c usbtiny -p m48 -U flash:w:life.hex

However, it is much slower than the complete kit version.

How then do I remake the hex file?

CaseyScalf
 
Posts: 127
Joined: Wed Nov 05, 2014 3:07 am

Re: Current Mac AVR Strategy? x Game of Life

by CaseyScalf on Tue Mar 12, 2019 4:00 am

Alrighty, so I think I found out why the hex I uploaded does not run the same as th code from the kit.

That is because the Atmega48v 10PU chips are not created equal!

The ones from the kit have a "1407" on the top of the chip and the ones I ordered as suggested in the parts list have a 1409.

Upon further inspection the 1409 does not run the Game of Life at all. It blinks like it. But it is not it. Also, it's not just slow. The speed is intermittent.

Can I change anything to help this?

How do I find the appropriate chip? I have not found a listing that delineates 1407 vs 1409.

Thank you,

CaseyScalf
 
Posts: 127
Joined: Wed Nov 05, 2014 3:07 am

Re: Current Mac AVR Strategy? x Game of Life

by westfw on Tue Mar 12, 2019 5:02 am

However, it is much slower than the complete kit version.

You probably need to set the fuses as well, so the chip will run at 8MHz instead of 1MHz (the "new chip default")
Probably something like:
Code: Select all | TOGGLE FULL SIZE
avrdude -c usbtiny -p m48  -U lfuse:w:0xE2:m  -U flash:w:life.hex


The ones from the kit have a "1407" on the top of the chip and the ones I ordered as suggested in the parts list have a 1409.

Those are probably date codes that shouldn't matter (7th week of 2014 vs 9th week?)
User avatar
westfw
 
Posts: 1509
Joined: Fri Apr 27, 2007 1:01 pm
Location: SF Bay area

Re: Current Mac AVR Strategy? x Game of Life

by CaseyScalf on Tue Mar 12, 2019 5:56 am

Thank you so much that is an excellent tip! I can't wait to try that out this morning.

Is setting the fuses common? Should I anticipate this in the future when programming blank chips?

CaseyScalf
 
Posts: 127
Joined: Wed Nov 05, 2014 3:07 am

Re: Current Mac AVR Strategy? x Game of Life

by westfw on Tue Mar 12, 2019 7:43 pm

Is setting the fuses common? Should I anticipate this in the future when programming blank chips?

Yes, when you're working with factory-fresh chips. It's one of the things that is (hopefully) unnecessary when you work with arduino-class "board" products (they should already have the fuses set appropriate, and a bootloader installed.)

Be careful - you can "brick" chips if you set the fuses incorrectly:
1) enabling "debugWire" when you don't have a debugWire programmer, or when the board interferes with debugwire (I just ran into this one last night!)
2) configuring for an external crystal or clock, when none is present.
3) disabling the RESET pin.
User avatar
westfw
 
Posts: 1509
Joined: Fri Apr 27, 2007 1:01 pm
Location: SF Bay area

Re: Current Mac AVR Strategy? x Game of Life

by CaseyScalf on Tue Mar 12, 2019 8:14 pm

It totally worked!

Thank you so much for all the help.

How did you know to use that hex value for the FUSE command? Did you look this up in the datasheet?

Just trying to get an idea for how to figure this out in the future.

CaseyScalf
 
Posts: 127
Joined: Wed Nov 05, 2014 3:07 am

Re: Current Mac AVR Strategy? x Game of Life

by westfw on Wed Mar 13, 2019 9:52 pm

How did you know to use that hex value for the FUSE command? Did you look this up in the datasheet?

You can get the info from the datasheet (careful - a feature is "enabled" by setting it's value to 0!)

But there's this wonderful online calculator: http://www.engbedded.com/fusecalc/
User avatar
westfw
 
Posts: 1509
Joined: Fri Apr 27, 2007 1:01 pm
Location: SF Bay area

Please be positive and constructive with your questions and comments.