Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

problem in using arrey & ADC using 16f777

Status
Not open for further replies.

kappa_am

Full Member level 6
Full Member level 6
Joined
Jul 16, 2012
Messages
331
Helped
19
Reputation
38
Reaction score
19
Trophy points
1,298
Location
Vancouver
Visit site
Activity points
3,859
hi,
I have written following program to convert ten analog inputs to digital signals, and put appropriate output regarding to comparison with REF signal (not determined yet). we use pin Vref- and Vref+ (AN2 & AN3) as voltage reference and AN12 pin as external interrupt.
when I use two dimensional signal "if state", the simulation shows that program execution time increase drastically,while it is just a 3*3 matrix.
I would be grateful if you help me in this respect. it also is appreciated if you take a look at the code and mention its defects.

Thank you

Code:
   unsigned int ADRES;
   unsigned short OUTM[3];
   unsigned short ph, cap, cap2;
   unsigned short REFC[3][3];
   unsigned char ADL_byte, ADH_byte;
   unsigned int ADR;
interrupt(void) {
unsigned short rep;
if (INTCON.INTF)
{
INTCON.INTF=0;
rep=0;
rep=(PORTB.B7<<1)|PORTB.B6;
 PORTD= (OUTM[rep]<<2) | rep;
}
}
 unsigned int ADREAD(unsigned char channel){
   if(channel.B3 != 0){
    channel.B3=0;
    ADCON0=0x83 | (channel<<3);
     }
   else
   { ADCON0=0x81 | (channel<<3);
    }
   // delay_us(20)
   GO_DONE_BIT=1;
   while(GO_DONE_BIT);
   ADL_byte=ADRESL;
   ADH_byte=ADRESH;
   ADR=(ADH_byte<<8)| ADL_byte;
   return ADR;
   }
void main() {
  OPTION_REG= 0xc7;
  INTCON=0x90;
  CMCON=7;
  ADCON1=0xB0;
  ADCON2=0x30;
  TRISD=0x00;
  PORTD=0x00;
  while(1)
  {
    cap2=0  ;
  for (ph=0; ph<3; ph++)
   {
    for (cap=0; cap<3; cap++)
    { if (ph==0 || cap>1) cap2=cap2+2;
      ADRES=ADREAD(cap2);
      ADRES=ADRES>>2;
      if(ADRES<REFC[ph][cap]) OUTM[ph] |= (1<<cap);
      else if(ADRES>REFC[ph][cap]) OUTM[ph]&= ~(1<<cap) ;
      else OUTM[ph] |= (1<<(cap+3))=1;
      cap2+=1 ;
     }
   }
  }
  }
 
Last edited:

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top