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 CCS Technical Support

Problem read analog LTC1298, Please Help

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



Joined: 14 Jun 2012
Posts: 8

View user's profile Send private message

Problem read analog LTC1298, Please Help
PostPosted: Thu Jun 14, 2012 11:22 pm     Reply with quote

Help me, Please.
I use LTC1298 + PIC16F877A.
I read the voltage and display 4 Led 7 seg. I use library "ltc1298.c". Read analog from CH0 and display Led.
My problem: But, for any input voltage, LTC1298 always read 5000 (5v).
"ltc1298" :
temp=data/div;
div=0x3330;

When display 5000 => data = 65520 = FFF0 (that time MSB=11111111 and LSB= 11110000)

I create function convert_to_volt for myself to suit for display Led and it's working fine. There is only one problem left. This is read analog from LTC.
I don't understand, Why is that?
main():
Code:

long int data;
adc_init();   
do
  {
    data=read_analog(0);    //  ??????
    Display_LTC(data);     //Display Led 7 seg =>ok (tested)
   }while(TRUE);

In "ltc1298.c", I have changed:
Code:

#ifndef ADC_CS

#define ADC_CLK  PIN_C4
#define ADC_DOUT PIN_C5
#define ADC_DIN  PIN_C6
#define ADC_CS   PIN_C7

#endif


That is my problem. Please help me.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Jun 15, 2012 4:19 pm     Reply with quote

Quote:
#ifndef ADC_CS

#define ADC_CLK PIN_C4
#define ADC_DOUT PIN_C5
#define ADC_DIN PIN_C6
#define ADC_CS PIN_C7

#endif

Pins C6 and C7 are used by the hardware UART, for your RS-232
communication with your PC. (To display the results on a terminal
window, such as TeraTerm). Don't use the UART pins for the LTC1298.
Choose some other pins.

Also, post your complete test program. Don't post ltc1298.c, because
we already have it. Just post your test program which calls the functions
in the ltc1298.c file. Don't post code fragments. Post the complete
program with #include, #fuses, #use delay, main(), variables, etc.
muatuyet_2012



Joined: 14 Jun 2012
Posts: 8

View user's profile Send private message

PostPosted: Sun Jun 17, 2012 9:40 pm     Reply with quote

Thanks for your suggestion.

This is my program:
Code:

#include <16F877A.h>
#include <def_16f877a.h>
#use delay(clock=20000000)
#fuses NOWDT,HS,NOPUT,NOPROTECT,NODEBUG,NOBROWNOUT,NOLVP,NOCPD,NOWRT

#include <ltc1298.c>
#use fast_io(c) //trans + ltc
#use fast_io(d)  //led
#bit U=PortC.3
#bit D=PortC.2
#bit H=PortC.1
#bit T=PortC.0

const unsigned char seg[10]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90};

void convert_to_volts( long int data, char volts[4])
{
     BYTE k;
     long int temp,div;
    div=0x3330;
    for(k=0;k<=3;k++)
     {
        temp=data/div;
        volts[k]=(BYTE)temp;
        temp=div*(BYTE)temp;
        data=data-temp;
        div=div/10;
     } 
}

void Display_LTC(long int data)
{
   int8 Th,Hr,Do,Un,i;
   char volts[4];
   convert_to_volts(data,volts);   
   Un=volts[3];
   Do=volts[2];
   Hr=volts[1];
   Th=volts[0];
   
   for(i=0;i<100;i++)
     {
       U=0;D=1;H=1;T=1;
       portd=seg[Un];
       delay_us(100);

       U=1;D=0;H=1;T=1;
       portd=seg[Do];   
       delay_us(100);
 
       U=1;D=1;H=0;T=1;
       portd=seg[Hr];
       delay_us(100);

       U=1;D=1;H=1;T=0;
       portd=seg[Th];
       delay_us(100);
     }
}

void main()
{
   long int DL;
   set_tris_c(0x00);
   set_tris_d(0x00);     
     do
      {
       DL=read_analog(0);
       Display_LTC(DL);
      }while(TRUE);
}


Please, contribute your ideas. Thanks all.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Jun 17, 2012 10:23 pm     Reply with quote

Your code doesn't compile. It has large numbers of compiler errors.

Quote:

int8 Th,Hr,Do,Un,i;

You are using a keyword as a variable name. That's not allowed in C.
"Do" is a keyword for the do-while statement. You can't use it !


Quote:

#define ADC_CLK PIN_C4
#define ADC_DOUT PIN_C5
#define ADC_DIN PIN_C6
#define ADC_CS PIN_C7

#use fast_io(c) //trans + ltc
#use fast_io(d) //led

void main()
{
long int DL;
set_tris_c(0x00);
set_tris_d(0x00);

Here you are using fast i/o. Then you set PortC to "all outputs". But
that's wrong. The PIC must be able to read from the LTC1298. It's
an A/D converter and the PIC must read the result. Don't use fast i/o.
It's not necessary, and it only causes errors for people that are new to
CCS and to PICs. Delete both of the #use fast_io lines.
muatuyet_2012



Joined: 14 Jun 2012
Posts: 8

View user's profile Send private message

PostPosted: Sun Jun 17, 2012 11:02 pm     Reply with quote

I did it!
You're really enthusiastic.
Thanks you so much!
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