Current Mac AVR Strategy? x Game of Life

USB AVR Programmer and SPI interface. Adafruit's USBtinyISP.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
CaseyScalf
 
Posts: 149
Joined: Wed Nov 05, 2014 3:07 am

Current Mac AVR Strategy? x Game of Life

Post by CaseyScalf »

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,

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: Current Mac AVR Strategy? x Game of Life

Post by adafruit_support_rick »

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.

User avatar
CaseyScalf
 
Posts: 149
Joined: Wed Nov 05, 2014 3:07 am

Re: Current Mac AVR Strategy? x Game of Life

Post by CaseyScalf »

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!

User avatar
CaseyScalf
 
Posts: 149
Joined: Wed Nov 05, 2014 3:07 am

Re: Current Mac AVR Strategy? x Game of Life

Post by CaseyScalf »

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,

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: Current Mac AVR Strategy? x Game of Life

Post by adafruit_support_rick »

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

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.

User avatar
CaseyScalf
 
Posts: 149
Joined: Wed Nov 05, 2014 3:07 am

Re: Current Mac AVR Strategy? x Game of Life

Post by CaseyScalf »

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!

User avatar
steven_conaway
 
Posts: 41
Joined: Fri May 20, 2016 9:18 pm

Re: Current Mac AVR Strategy? x Game of Life

Post by steven_conaway »

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

User avatar
CaseyScalf
 
Posts: 149
Joined: Wed Nov 05, 2014 3:07 am

Re: Current Mac AVR Strategy? x Game of Life

Post by CaseyScalf »

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,

User avatar
CaseyScalf
 
Posts: 149
Joined: Wed Nov 05, 2014 3:07 am

Re: Current Mac AVR Strategy? x Game of Life

Post by CaseyScalf »

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?

User avatar
CaseyScalf
 
Posts: 149
Joined: Wed Nov 05, 2014 3:07 am

Re: Current Mac AVR Strategy? x Game of Life

Post by CaseyScalf »

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,

User avatar
westfw
 
Posts: 2005
Joined: Fri Apr 27, 2007 1:01 pm

Re: Current Mac AVR Strategy? x Game of Life

Post by westfw »

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

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
CaseyScalf
 
Posts: 149
Joined: Wed Nov 05, 2014 3:07 am

Re: Current Mac AVR Strategy? x Game of Life

Post by CaseyScalf »

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?

User avatar
westfw
 
Posts: 2005
Joined: Fri Apr 27, 2007 1:01 pm

Re: Current Mac AVR Strategy? x Game of Life

Post by westfw »

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
CaseyScalf
 
Posts: 149
Joined: Wed Nov 05, 2014 3:07 am

Re: Current Mac AVR Strategy? x Game of Life

Post by CaseyScalf »

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.

User avatar
westfw
 
Posts: 2005
Joined: Fri Apr 27, 2007 1:01 pm

Re: Current Mac AVR Strategy? x Game of Life

Post by westfw »

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/

Locked
Please be positive and constructive with your questions and comments.

Return to “USBtinyISP”