Help using PIC?

Hi, I wasn't sure if this belonged in the project sub-forum, but I'll just post it here. This is my first project concerning the use of microcontrollers, and any help would be greatly appreciated!

I have a project that is receiving data from a GPS, and I am not sure how I should store the data. I have a PIC in my possession (PIC 18LF 4525), but I don't feel that it has enough EEPROM for me to store the data from the GPS directly on it. Is there some way for me to configure an SD card to store the data, or some other memory chip? Thank you!

How about an Uno and a datalogging shield?

Right! I was thinking about doing that instead, but my project is to launch a HAB, and I want the lightest payload possible (not that Arduino isn't light), hence the PIC. The PIC can also be integrated with my other components onto a single board, so it can occupy less payload space that way. Is it complicated to interface axillary memory?

your talking chevy, this is the ford group

pic's and avr's are two competing projects, and in all realistic manner does the same thing (not counting that microchip, the maker of PIC micro-controllers have some of the worst development software this side of TI, but they are stupid cheap)

arduino is a noobie oriented set of libraries, IDE and form-factor based on AVR chips at its core, there are attempts to bridge some gaps but all in all why use a 8 pin PIC and then choose an AVR development system to try and mutilate, just choose a 8 pin AVR (or whatever) unless your buying millions of the things your talking about spending less than 10 bucks for the BIGGEST avr, or PIC

choose what you want to work with

if you have a PIC(which if its scavenged means its probably non programmable) then you need to find a pic system

Sorry, so just to clarify, you are suggesting that I should use an AVR Microcontroller (not Arduino?) because they are more newbie oriented? What AVR would you suggest for maximum memory storage?

I have a programmer with a DB25 connector (it is old), which I think would allow me to rewrite the PIC if I decided to use it. And yes, it is scavenged :).

mrShrimp:
Sorry, so just to clarify, you are suggesting that I should use an AVR Microcontroller (not Arduino?) because they are more newbie oriented? What AVR would you suggest for maximum memory storage?

Rather than saying "maximum memory" perhaps specify how much RAM, EEPROM, and program memory you actually require. An external SD card is always an option.

The Arduino uses an AVR processor so they aren't exactly mutually exclusive.

... but my project is to launch a HAB ...

I'm guessing a high altitude balloon?

The difference in weight (if any) of a couple of grams won't make much difference, I would have thought. However in any system the more memory you demand the heavier the chip will tend to be. But really, if you are just measuring stuff, storing in a (say) 4 Gb SD card will give you all the storage you need, so a cheap simple processor (like the Atmega328P) should be perfectly adequate.

A 2 Gb SD card I have here weighs 1.7g, so if your balloon can't manage to carry a chip of around 2 grams you have problems.

you are suggesting that I should use an AVR Microcontroller (not Arduino?)

no I am suggesting that arduino uses AVR micros, not microchip PIC's

because they are more newbie oriented?

no becuase arduino is more newbie oriented, and arduino uses AVR micro-controllers, there are some adaptations that will allow you to use pic micro-controllers, but there are doezens of models, your chances are slim

same with avr controllers, but since arduino's are originally based on avr controllers the chances greatly increase. Its like PC software, you have a mac, we use windows, you want to write windows software that runs on mac, its not impossible, but ...

The PIC can also be integrated with my other components onto a single board, so it can occupy less payload space that way

Hmm... I'm definitely not a hw guy, but from what I've seen arount the 'net, self-made arduino boards shouldn't be that difficult to build.
Also, there are commercial arduino boards that are quite small. Nano and mini, here: http://arduino.cc/en/Main/Hardware

My 2 cents

:slight_smile:

A few possibilities:

  1. Microchip has a SD library for the 18F chips. And there are various ports of SD card libraries for the 18F chips too.
  2. You can use flash space to store data.
  3. You can use an outside EEPROM chip for that. 1 8pdip + two resistors. Easy to port.
    ...

Thank you all for your help! I do want to be able to use an SD card, because the final result will be prettier, but it looks rather complicated. If I wanted to use built in flash memory, would I get a benefit from buying an newer AVR microcontroller compared to what I already have? (PIC18LF4525-I/P Datasheet Microchip, Download PDF)

mrShrimp:
If I wanted to use built in flash memory, would I get a benefit from buying an newer AVR microcontroller compared to what I already have? (PIC18LF4525-I/P Datasheet Microchip, Download PDF)

You really have to compare individual chips of the two lines to get a meaningful answer.

For example, the Uno uses an ATmega328 and the PIC you linked to is similar in some areas (e.g. operating voltages, resolution of ADC, etc...) and better (maximum clock speed, flash memory capacity, RAM capacity, etc...) in quite a few. On the other hand, the Mega 2560 uses an ATmega2560 which has more total I/O pins, more RAM, much more flash memory, etc... About the only thing that your PIC chip has on the ATmega2560 is raw clock speed (it is possible to run most ATmegas up to 20 MHz, though Arduinos default to 16 MHz). This can make a difference in some applications, but much fewer than you might think.

Of course as mentioned in previous responses all AVR chips, and especially Arduino compatible ones, have one significant advantage over standard PICs; an easier to use programming tool chain. Although I've found PICAXE to be an effective third-party solution for programming PICs, but off-hand I don't know if the PIC you linked to can be used with PICAXE. Even if it could you'd have either buy a new one with the bootloader or put the bootloard on yourself. In any case, I prefer the C/C++ based Arduino IDE compared to either PICAXE's Basic based IDE or having to use assembly.

That chip is self-programmable.

Two ways to approach it:

  1. you can use a bootloader - they are many of them floating around;
  2. you can code it yourself - either by manipulating the registers or pick a compiler that has a canned solution for that.

Neither is complicated.

IDE is highly subjective and it is hard to say which is superior to somebody else.

With PIC, you are limited to mostly Microchip (PICC/C18/XC8 + MPLAB/MPLAB-X), CCS, mikroe, and maybe other minor compilers (IAR I think made a PIC18 compiler but stopped some years back). Both CCS and mikroe are similar to Arduino in their uses of "libraries" to speed up development. The free PIC18 peripheral libraries from Microchip is pretty good as well.

With AVR, you are limited to ATMEL / GCC, IAR, CVAVR, ICCAVR, and maybe others. CCVAVR / ICCAVR are similar to Arduino from a "library" perspective.

with Arduino, you are limited to Arduino, obviously.

with Arduino, you are limited to Arduino, obviously.

I'm not sure what this means. You can use the Atmega328 chip, outside an Arduino. It can be programmed easily enough using various methods, one of which is to use the Arduino IDE. Or, you can compile at the "command line" level using avr-gcc and "make".

I presume you won't actually fling an Arduino development board into the stratosphere, there would be a few reasons not to, including weight and power consumption.

I do want to be able to use an SD card, because the final result will be prettier, but it looks rather complicated.

The SDfat library makes writing files to an SD card pretty trivial. Something like this:

  SdFile myFile;

  if (myFile.open ("foo.txt", O_WRITE | O_CREAT | O_TRUNC)) 
    {
    // if opened OK
    myFile.println ("some_data");     
    myFile.close ();
    }

I wouldn't call that complicated.

You can use the Atmega328 chip, outside an Arduino.

That is what I think I should do. I don't have a spare ATmega328 (which is why I asked about the PIC), but I have an ArduinoUNO that serves another purpose in the project. Could I use that to program another ATmega328 by simply swapping out the chips? This instructable seems to cover how to set the chip up on a board: http://www.instructables.com/id/Standalone-Arduino-ATMega-chip-on-breadboard/. Are there some other things I should know before trying this?

As for the SD card, I think I will do a test run that will log coordinates to the flash memory, and if the memory goes below a critical point, alert me somehow. If that happens, I will have to integrate the SD, but it doesn't hurt to try. :slight_smile:

You can use the Uno as an SPI programmer, yes. There are tutorial pages about that (Arduino as ISP) and the relevant sketch comes with the Arduino.

You can log to EEPROM, of which you have 1 Kb on the Atmega328. Simple arithmetic should show whether you have enough of that to store the amount of data you have in mind.

Huh, I was under the impression that flash memory was another type of EEPROM. I am pretty sure 32Kb will be enough, but 1Kb certainly won't be. This is where I got that info (I am not sure of the site's reliability): http://www.seattlerobotics.org/encoder/sep97/basics.html

I was under the impression that flash memory was another type of EEPROM.

Technically, flash rom is another type of "electrically erasable" rom, but this doesn't tell us how it can or can't be used in practice :slight_smile:

Flash ROM is where the program code is stored. EEPROM is the user-accessible one. So basically yes, you just have 1KB to store data. To increase that you have to go the sd route or add an external (i2c ?) eeprom chip.

I was under the impression that flash memory was another type of EEPROM

Yes, and no. The 32k of "flash program memory" in an ATmega328 is not usable for writing data, and has a limited number of cycles when being written by anything. The EEPROM is much more easily writable, but is only 1k. An SD card offers ridiculous amounts of storage, at the expense of complexity (a filesystem and whatnot.) (If you use the arduino environment, a lot of that complexity may be hidden by pre-written libraries.) In between, you can find external serial EEPROM and "Dataflash" chips that have intermediate amounts of storage, and intermediate complexity...

westfw:

I was under the impression that flash memory was another type of EEPROM

Yes, and no. The 32k of "flash program memory" in an ATmega328 is not usable for writing data, and has a limited number of cycles when being written by anything.

Technically both the Flash and the EEPROM have a limited amount of write/erase cycles, though in the AVR chips used in Arduinos there is at least an order of magnitude difference (i.e. a factor of ten) in the minimum times a memory space can be rewritten in EEPROM. For example in Section 7, "AVR Memories", of the ATmega328 datasheet it states; "The Flash memory has an endurance of at least 10,000 write/erase cycles" and "The EEPROM has an endurance of at least 100,000 write/erase cycles".