Eeprom memory, ADC and USART from PIC18F4550

Discussion in 'Embedded Systems and Microcontrollers' started by Tainara, Jul 7, 2015.

  1. Tainara

    Thread Starter New Member

    Sep 10, 2014

    I am trying to read the acceleration of three axis of an acellerometer with the microcontroller PIC18F4550's ADC and store the samples data at its eeprom memory. Also after filling the eeprom memory I want to send the data to computer via bluetooth using serial communication.

    According the datasheet the eeprom memory has 128 bytes but PIC ADC uses 10 bits so I am trying to store 64 samples, using 2 bytes from eeprom to each sample. And I am trying to collect one sample for second by now. When it reaches the 64 samples written at eeprom the microcontroller has to wait a command from computer and after this command sample by sample will be sent to the computer.

    I am not confident with the program I made though so I would like to ask your opinion and if you have any advice, please.

    Here is my program:
  2. tshuck

    Well-Known Member

    Oct 18, 2012
    A few things:
    1. Post the datasheet for the accelerometer so we can see how it operates and what the interface is.
    2. It doesn't seem like you really need to use the EEPROM to store your data (it has a limited number of write cycles), you may want to consider using RAM to store it since it's just getting dumped to a computer anyway.
    3. If you don't need the full 10-bit resolution of the ADC, take the most significant 8 bits to alleviate storage waste. Or, you could pack the bits, but that would be a bit more complicated.
    Edit: also, your ADC function will return erroneous results.
    you need to shift the bits to the appropriate places - see left/right justification in the ADC section of the datasheet.
    Last edited: Jul 7, 2015
  3. Tainara

    Thread Starter New Member

    Sep 10, 2014
    I am using an ADXL335 accelerometer which I uploaded the datasheet and breakout board scheme.
    Well, I did the ADC function that way to return a value which I could "easily" manipulate to separate the msb from the lsb to store them in separate bytes of the memory because of the 10 bit resolution and I'd set the values according to the justification only when reading data from memory. Anyway I'd find problems in using the three axis data individually and simultaneously. But with your tips I think I can make changes to improve my program thank you.
  4. atferrari

    AAC Fanatic!

    Jan 6, 2004
    Eu acho...

    While using EEprom is simple, better if you do all in RAM as suggested.

    Later you can send as many as you like using INDFx pointers (a powerful thing).