PDA

View Full Version : save and load "bits" in eeprom...



martintorres
- 21st September 2012, 05:52
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:


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:


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

HenrikOlsson
- 21st September 2012, 06:28
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:


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:

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

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:

PortD = Adc.LowByte
PortB = Adc.HighByte

/Henrik.

martintorres
- 21st September 2012, 19:29
6669
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

martintorres
- 22nd September 2012, 01:06
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?

mackrackit
- 22nd September 2012, 03:03
Add a "txt" to the file name.
xxx.rar.txt

HenrikOlsson
- 22nd September 2012, 07:46
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.

martintorres
- 22nd September 2012, 19:28
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

6670