save and load "bits" in eeprom...


Closed Thread
Results 1 to 7 of 7
  1. #1
    Join Date
    Aug 2012
    Location
    Comodoro Rivadavia - Patagonia Argentina
    Posts
    51

    Default save and load "bits" in eeprom...

    Hello friends, I am tortured with a PIC16F877 and Proteus EEPROM memory (for now I simulate it and then see if we practice on a protoboard) ...
    I stuck to the following issue: how I can save a 10bits variable in eeprom?

    For example, today I read the sign and put it in a format of 10bits:

    Code:
    DEFINE ADC_BITS 10        
    DEFINE ADC_CLOCK 3    
    DEFINE ADC_SAMPLEUS 50
    
    Adc VAR WORD 
    
    D0 VAR Adc.0
    D1 VAR Adc.1
    D2 VAR Adc.2
    D3 VAR Adc.3
    D4 VAR Adc.4
    D5 VAR Adc.5
    D6 VAR Adc.6
    D7 VAR Adc.7
    D8 VAR Adc.8
    D9 VAR Adc.9
    I currently play for the variable in a 10-bit DAC I do is this:

    Code:
    TRISA = %11111111
    TRISB = %00000000
    TRISD = %00000000
    
    ADCON1.7 = 1
    
    Inicio:
       
       ADCIN 0,Adc
       
       PORTD.0 = D0
       PORTD.1 = D1
       PORTD.2 = D2
       PORTD.3 = D3
       PORTD.4 = D4
       PORTD.5 = D5
       PORTD.6 = D6
       PORTD.7 = D7
       PORTB.0 = D8
       PORTB.1 = D9
     
    GoTo Inicio
    What I like to do now is see how these bits can be saved in an EEPROM, then call them and load them into the various bits of the DAC port to play ...
    Basically, what I'm trying to do is a kind of mini chipcorder, as well as this program, you can add sound, and play it in real time by the DAC (well, not very accurate, but this would be the beginning)
    Regards
    Martin Patagonia Argentina

  2. #2
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,604


    Did you find this post helpful? Yes | No

    Default Re: save and load "bits" in eeprom...

    Hi,
    Stop thinking of it as individual bits. You have a 16-bit variable (a WORD, 2 bytes) that you've called Adc - in that variable 16 bit variable you have your 10 individual "bits". To save your two bytes to the EEPROM:
    Code:
    WRITE 0, Adc.HighByte    ' Store the high byte of the WORD variable at adress 0 in EEPROM
    WRITE 1, Adc.LowByte   ' Store the low byte of the WORD variable at adress 1 in EEPROM
    Then to read it out and put it back in the variable called Adc:
    Code:
    READ 0, Adc.HighByte
    READ 1, Adc.LowByte
    And again, there's really no need to write each indivudal bit to the port like your doing (perhaps there's another reason not shown?), simply do
    Code:
    PortD = Adc.LowByte
    PortB.0 = Adc.8
    PortB.1 = Adc.9
    Or, if you aren't using the top 6 bits of PortB for anything, simply:
    Code:
    PortD = Adc.LowByte
    PortB = Adc.HighByte
    /Henrik.

  3. #3
    Join Date
    Aug 2012
    Location
    Comodoro Rivadavia - Patagonia Argentina
    Posts
    51


    Did you find this post helpful? Yes | No

    Default Re: save and load "bits" in eeprom...

    Name:  mty you're the best.jpg
Views: 40703
Size:  24.3 KB
    Thanks ... the truth, You opened my eyes. Tonight I will check your recommendation and I mention ... if it works, I upload the entire project to share

  4. #4
    Join Date
    Aug 2012
    Location
    Comodoro Rivadavia - Patagonia Argentina
    Posts
    51


    Did you find this post helpful? Yes | No

    Default Re: save and load "bits" in eeprom...

    Unfortunately, I could not run with the idea that there were armed according to his previously played ... I am assuming that the output frequency slowed to save and then go back to get the bits.
    Here is the audio player of human voice in real time with a resolution of 10 bits. Maybe someday someone can improve it and finish...
    regards

    PD: How I can upload a file. Rar with all available material?

  5. #5
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default Re: save and load "bits" in eeprom...

    Add a "txt" to the file name.
    xxx.rar.txt
    Dave
    Always wear safety glasses while programming.

  6. #6
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,604


    Did you find this post helpful? Yes | No

    Default Re: save and load "bits" in eeprom...

    Not sure I understand exactly what you're trying to do. Are you trying to record sound with the on chip analog to digital converter and store that, in real time, in EEPROM on a 16F877?

    First, the WRITE command is self timed and, according to the manual, takes up to 10ms. You're doing two of those so ~20ms or a whopping sample rate of 50Hz - not that great for audio. Second, the EEPROM on that device is only 256 bytes, since each of your samples are two bytes you can save 128 samples. Even at the not usable 50Hz sample rate that's only ~2.5 seconds. To get anything usable for speach I'd say you need a sample rate of 8kHz which would give you a whopping storage of 16ms.

    Maby you can use WRITECODE and store it in the FLASH instead of in EEPROM but your best bet would be to get somekind of external memory device.

    /Henrik.

  7. #7
    Join Date
    Aug 2012
    Location
    Comodoro Rivadavia - Patagonia Argentina
    Posts
    51


    Did you find this post helpful? Yes | No

    Default Re: save and load "bits" in eeprom...

    Thank mackrackit!!! I upload the files there to watch it and simulate it.
    Friend Henrik; Initially I did was play the sound file in real time. That is, the read 10-bit ADC, and simultaneously reproduce it in the DAC 10 bits. Until here, all right.
    The issue was that after cosidere in store this data in a memory space pra see s could play, obviously, I would have escpao that reproduction uqe 20Khz frequency range in ... I'm thinking of another way to deal with this to see if I get to the main point ... a kind of chip corder, but entirely made ​​in PBP
    regards

    SOUNDbasic.rar.txt

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts