View previous topic :: View next topic |
Author |
Message |
pvol
Joined: 10 Oct 2008 Posts: 46 Location: GREECE
|
10-bit result A/D |
Posted: Tue Dec 09, 2008 3:45 am |
|
|
hello everybody
i'm working on 16f876-7
and i want to storage a 10 bit result A\D in internal
eeprom
can i storage whole 10 bit number?/?
or i have to split in 2 bytes?// |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
pvol
Joined: 10 Oct 2008 Posts: 46 Location: GREECE
|
|
Posted: Thu Dec 11, 2008 2:18 pm |
|
|
I have done an attempt to store these values
to some tables as you can see in this code.
Every 1ms (from interrupt) I will take 20 samples
for each table.
When samples =60 then interrupt disabled
and I get the numbers over 232.
...seems to work but not 100%.
Sometimes works great, sometimes confused,
and "pause" then start again.
Do I have fault somewhere?
Code: | #include <16F877.h>
#device ADC=10
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#byte PORTA = 0x05
#byte PORTB = 0x06
#byte PORTC = 0x07
#use RS232(baud=115200, xmit=PIN_C6, rcv=PIN_C7)
int count=0;
int16 A[20];
int16 B[20];
int16 C[20];
int16 D[20];
int16 E[20];
int16 F[20];
int flag=1;
int i=0;
#int_RTCC
void RTCC_isr(){
set_RTCC(100);
count++;
if(count<=20){
set_adc_channel( 0 );
delay_us(50);
A[i] = read_ADC();
set_adc_channel(1);
delay_us(50);
B[i]=read_ADC();
i++;
if(i>=19)
i=0;
}
if((count>20)&&(count<=40)){
set_adc_channel( 0 );
delay_us(50);
C[i] = read_ADC();
set_adc_channel(1);
delay_us(50);
D[i]=read_ADC();
i++;
if(i>=19)
i=0;
}
if((count>40)&&(count<=60)){
set_adc_channel( 0 );
delay_us(50);
E[i] = read_ADC();
set_adc_channel(1);
delay_us(50);
F[i]=read_ADC();
i++;
if(i>=19){
i=0;
flag=0;
count = 0;
}
}
return;
}
void main (void){
set_tris_a(0xff);
set_tris_b(0x00);
setup_adc_ports( AN0_AN1_AN3 );
setup_adc(ADC_CLOCK_DIV_32);
setup_counters(RTCC_internal,RTCC_div_16);
set_RTCC(100);
set_tris_c(0x01);
enable_interrupts (INT_RTCC);
enable_interrupts( global);
PORTC=0x00;
while(TRUE){
while(flag);
disable_interrupts(INT_RTCC);
for(i=0;i<=19;i++){
i=0;i<=19
printf ("%ld\n",A[i]);
printf("%ld\n",B[i]);
}
for(i=0;i<=19;i++){ i=0;i<=19
printf ("%ld\n",C[i]);
printf(" %ld\n",D[i]);
}
for(i=0;i<=19;i++){ einai i=0;i<=19
printf (" %ld\n",E[i]);
printf("%ld\n",F[i]);
}
flag=1;
count=0;
set_RTCC(100);
enable_interrupts(INT_RTCC);
}
} |
|
|
|
Ttelmah Guest
|
|
Posted: Thu Dec 11, 2008 3:36 pm |
|
|
You are not using the internal EEPROM at all...
Best Wishes |
|
|
pvol
Joined: 10 Oct 2008 Posts: 46 Location: GREECE
|
|
Posted: Fri Dec 12, 2008 1:00 am |
|
|
Thanks for answer!
Yes, I know that!!
Is it wrong to do it that way?? |
|
|
|