General Forums >> General Programming

yodude



Reged: May 22 2006
Posts: 1
ADC with pic16f877
      Fri May 26 2006 08:15 PM

hi everyone,
I am using a pic16f877 @ 20Mhz. what i am trying to do here is let the timer1 run and when it overflows load the ADC value just converted, then let the timr time out and then reload again...

I have loaded values into the timer to allow for faster overflow as per my requirements.

whats happening now is that we i input only 0.2v on the analogue pin the timer overflows.. I would expect it to overflow steadily from 0-5v for a 10 bit adc result..

any ideas?

here is the code..

#include <pic.h>
#include <delay.h>

__CONFIG(WDTDIS);


#define clear 0
#define on 1
#define off 0
#define time_l 0x00
#define time_h 0xFB
bit done;

//#define test

void init_ports(void);
void init_adc(void);


/**************************************************************************/

void init_ports(void){

INTCON = 0xC0; // GIE and PEIE enabled
TRISA = 0b00000010; // set port to input
TRISB = 0b00000000; // set port to output
PIE1 = 0x41; // ADIE, TMR1IE enabled
PIR1 = 0x01; // TMR1IF enabled
}

void init_adc(void){

ADCON0 = 0b10001001; // setup adc, RA1
ADCON1 = 0b00100000; // configure function port pin
T1CON = 0b00101000; // configure timer1 (prescale 1:4)
TMR1L = time_l;
TMR1H = time_h; //load values
ADRESL = clear; //clear a/d reg on start up
ADRESH = clear;
}

/*************************************************************************/
static void interrupt isr(void){

if (TMR1IF){

TMR1IF = clear;
if (done){

done = clear;
RB1 = on;
NOP();
NOP();
NOP();
NOP();
RB1 = off;
}

DelayUs(25);
ADGO = on;

if (ADIF){

ADIF = clear;
TMR1L = ADRESL;
TMR1H = ADRESH|time_h;
ADRESL = clear;
ADRESH = clear;
done = 1;
}
}
}
void main(void){

init_ports();
init_adc();
TMR1ON = on;
while(1){}
}

Post Extras Print Post   Remind Me!     Notify Moderator


Entire topic
Subject Posted by Posted on
* ADC with pic16f877 yodude Fri May 26 2006 08:15 PM

Extra information
0 registered and 8 anonymous users are browsing this forum.

Moderator:  Dan Henry, jtemples, mikerj, Andrew L 



Forum Permissions
      You cannot start new topics
      You cannot reply to topics
      HTML is enabled
      UBBCode is enabled

Rating:
Thread views: 2034

Rate this thread

Jump to

Contact Us | Privacy statement HI-TECH Software

Powered by UBB.threads™ 6.5.5