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

16f887A angular movement in deg of potentiomenter problem..

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







16f887A angular movement in deg of potentiomenter problem..
PostPosted: Mon Feb 13, 2006 8:52 pm     Reply with quote

Guys what is wrong with following code? Confused
I've a temperature sensor connected to PortA A0 and a potentiometer connected to A1.first I read the A0 AdC and delay for 20us and read ADC A1.
The problem is the value reading from the sensor is the same as the value reading from the potentiometer.If i avry the potentiometer, the values in both readin g vary.This is not suppose to be true as the two readings are different.
What is the problem?
Code:
#include <16f877a.h>
#device *=16
#device adc=10
#fuse HS,NOWDT,NOPROTECT,NOLVP,NOPUT
#use dleay(clock=20000000)
#include <lcd_driver.c>

#define Tr     0.35191  //potentiometer 1 revolution 360 degs                          // which  is 0V & 1023 adc counts.
                                //Tr=360/1023  gives deg/adc_cnt

struct time {
               int16 adcvals;
               int16 deg_temp;             
               int16 adc_ang_val;
                  }global_adc={0,0,0};

void read_adc_vals(void);
#int_TBE
TBE_isr()
{
    static int1 toggle=0;

    if(toggle) {
         toggle=0;
         global_adc.adcvals=read_adc(ADC_READ_ONLY);
         }
         else {
         toggle=1;
         read_adc(ADC_START_ONLY);
       }

}

#int_RDA
RDA_isr()
{

}

/*#int_TIMER0
TIMER0_isr()
{  //static int16 tick=0;
   // tick+=256;   //   set_timer0(206); 20 mhz clock, no prescaler, set
timer 0 to overflow in 35us
                    // 256-(.001024/(4*256/20000000))
 }*/


void main()
{

   //char cnt;
   setup_adc_ports(ALL_ANALOG);
   setup_adc(ADC_CLOCK_DIV_32);    //ADC_CLOCK_INTERNAL//SET adc conversion clock speed
                                   //TAD(per bit)=1/20Mhz X 32 = 0.16us ;Requires min. 12 TAD for 10 bit
                                   //Min. conversion time approx. 2us
   //set_adc_channel(0);             //Set ADC channel to port0(pin 2,AN0).
   //setup_timer_0(RTCC_INTERNAL|RTCC_DIV_2);
   // setup_psp(PSP_DISABLED);setup_spi(FALSE);setup_timer_1(T1_DISABLED);setup_timer_2(T2_DISABLED,0,1);
  // setup_comparator(NC_NC_NC_NC);setup_vref(FALSE);

enable_interrupts(INT_AD);/ enable_interrupts NT_TBE);enable_interrupts(INT_RDA);
   lcd_init();
  // enable_interrupts(INT_TIMER0);
   enable_interrupts(GLOBAL);             //printf("Sampling adc"

   lcd_gotoxy(2,1);
   lcd_putc("\fSampling....");
   delay_ms(1000);
   lcd_putc("\f");

while(1)
   {
   read_adc_vals();
   delay_ms(200);
   }

}

void read_adc_vals(void){
    static int32 avgvalz;
    static int16 adcvalz;
    static int16 adcarr[10];
     signed int8 cnt;
     static  float angul_deg;                   
         
     set_adc_channel(0);      //set channel to channel0

/*this loops are used to give smoother temperature*/
   for(cnt=0; cnt<10; cnt++)
       {
         adcarr[cnt]=global_adc.adcvals;
        }

       avgvalz=0;
       for(cnt=0; cnt<10; cnt++)
       {
         avgvalz +=adcarr[cnt];
        }
       
         delay_us(20);     
 
        set_adc_channel(1);   
        global_adc.adc_ang_val=read_adc(); 

/*Arithmatic calculations here*/
        adcvalz=avgvalz/10; //taking the averages values of temps
        global_adc.deg_temp = ((adcval - 559L)/2); //temperatures in deg
       
        angul_deg=(global_adc.adc_ang_val*Tr);     //Tr=360/1023
       
/*Print the results to the lcd display am using lcd*/
     lcd_gotoxy(8, 1);
     printf(LCD_PUTC," %04lu %02Lu\n\r",adcvalz,global_adc.deg_temp);
     
 lcd_gotoxy(8, 2);
 printf(LCD_PUTC," %04lu %Lu\n\r",global_adc.adc_ang_val,angul_deg);

 }


Have anyone ever done it before??
Help Idea
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