View previous topic :: View next topic |
Author |
Message |
pvol
Joined: 10 Oct 2008 Posts: 46 Location: GREECE
|
16bit table |
Posted: Sun Dec 28, 2008 11:03 am |
|
|
hi everybody!
I want to store 25 values to a 16 bit table
from an A/D conversion
every 0.8ms take sample and store it into table
when I take 25 samples disable timer0
and show at PC
but something goes wrong
the last value (and sometime first) is always wrong!
can u help me?
here is the code
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 cha1a[25];
int flag=1;
int i=0;
#int_RTCC
void RTCC_isr(){
set_RTCC(125);
output_high(PIN_B7);
count++;
if(count<=25){
set_adc_channel(3);
cha1a[i] = read_ADC();
i++;
if(i>=24){
flag=0;
count=0;
i=0; }
}
output_low(PIN_B7);
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_32);
set_RTCC(125);
set_tris_c(0x01);
enable_interrupts (INT_RTCC);
enable_interrupts( global);
while(TRUE){
while(flag);
disable_interrupts(INT_RTCC);
for(i=0;i<=24;i++){
printf ("%ld\n",cha1a[i]);}
set_RTCC(125);
enable_interrupts(INT_RTCC);
flag=1;
}
} |
to check this fault
i send from sensor zero value all time
(DC 0V)
and i see some very wrong values (256, 255, 126...)
|
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Sun Dec 28, 2008 11:34 am |
|
|
The last value is never written in your code. |
|
|
pvol
Joined: 10 Oct 2008 Posts: 46 Location: GREECE
|
|
Posted: Sun Dec 28, 2008 11:37 am |
|
|
can explain?
what i have wrong? |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Sun Dec 28, 2008 12:18 pm |
|
|
The code does exactly what you have written. After setting cha1a[23], i is reset. Thus cha1a[24]is never touched. |
|
|
pvol
Joined: 10 Oct 2008 Posts: 46 Location: GREECE
|
|
Posted: Sun Dec 28, 2008 12:58 pm |
|
|
thanks!
i change i>=25 and works!
but it is something more (i discover it right now)
well, i make two different programs
the first is to take at real time 25 samples (no store) every 0.8ms from lan
25*0.8=20ms or 50Hz
and works just fine
and the second is that
the first program is ok .
i have the same time at the second prog
but the differense is to store them
before show
the problem is that the second waveform
isn't same
is there any problem on table?
can u suggest something? |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Sun Dec 28, 2008 1:38 pm |
|
|
The table seems O.K. I think, a minimal delay is required between set_adc_channel(3); and read_adc(); |
|
|
pvol
Joined: 10 Oct 2008 Posts: 46 Location: GREECE
|
|
Posted: Sun Dec 28, 2008 2:21 pm |
|
|
thanks for interesting FvM
i'll check it!! |
|
|
|