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

10-bit result A/D

 
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

10-bit result A/D
PostPosted: Tue Dec 09, 2008 3:45 am     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Dec 09, 2008 12:48 pm     Reply with quote

Read and bookmark the CCS FAQ page:
http://www.ccsinfo.com/faq
Look at this section:
Quote:

Memory
How do I write variables to EEPROM that are not a byte?


Also, here is a post with sample code:
http://www.ccsinfo.com/forum/viewtopic.php?t=27405&start=5
pvol



Joined: 10 Oct 2008
Posts: 46
Location: GREECE

View user's profile Send private message

PostPosted: Thu Dec 11, 2008 2:18 pm     Reply with quote

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







PostPosted: Thu Dec 11, 2008 3:36 pm     Reply with quote

You are not using the internal EEPROM at all...

Best Wishes
pvol



Joined: 10 Oct 2008
Posts: 46
Location: GREECE

View user's profile Send private message

PostPosted: Fri Dec 12, 2008 1:00 am     Reply with quote

Thanks for answer!
Yes, I know that!!
Is it wrong to do it that way??
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