CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

16bit table

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
pvol



Joined: 10 Oct 2008
Posts: 46
Location: GREECE

View user's profile Send private message

16bit table
PostPosted: Sun Dec 28, 2008 11:03 am     Reply with quote

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...)
Confused
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Sun Dec 28, 2008 11:34 am     Reply with quote

The last value is never written in your code.
pvol



Joined: 10 Oct 2008
Posts: 46
Location: GREECE

View user's profile Send private message

PostPosted: Sun Dec 28, 2008 11:37 am     Reply with quote

can explain?
what i have wrong?
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Sun Dec 28, 2008 12:18 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Sun Dec 28, 2008 12:58 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Sun Dec 28, 2008 1:38 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Sun Dec 28, 2008 2:21 pm     Reply with quote

thanks for interesting FvM
i'll check it!! Very Happy
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group