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

16bit external A/D error

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



Joined: 20 Nov 2005
Posts: 16
Location: the Netherlands

View user's profile Send private message

16bit external A/D error
PostPosted: Wed Jun 07, 2006 6:35 am     Reply with quote

hi there,

I've hooked up this ic from maxim dallas-Max1134, http://pdfserv.maxim-ic.com/en/ds/MAX1134-MAX1135.pdf , with a 18F8722 running at 10mhz.
I have an external ref of 2.048 connected to the ic.
I can't seem to read the value right.Almost like only the msb is coming.For example i read 8192(0x2000) for a small 1.3v AA battery,16384 (0x4000) for 2 AA batteries(3.66v),32768 (0x8000) for 3 AA batteries. I am in unipolar mode,internal clock,control byte is sent ok and its value is 0xE5.

Anybody can suggest what went wrong with my 16bits read timming here?(figure 5 and 6,page 11 on datasheet ).Is it ok to read it just after CS is low again?I would super apreciate any idea.

Best Regards.


Code:
#include <18F8722.H>
#include <string.h>
#include <STDLIB.H>
#fuses HS, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock=10000000)
#use rs232(baud=19200, xmit=PIN_C6, rcv=PIN_C7)

#define NOP #asm nop #endasm

#define SPI_SI    PIN_A0 // SPI In pin
#define SPI_SO    PIN_A1 // SPI Out pin
#define SPI_SCK   PIN_A2 // SPI Out Clock pin
#define CS_MAX    PIN_A3
#define RST_MAX   PIN_A4
#define SSTRB     PIN_A5

int16 vector[250];
int i;
long val;

union split
{
int16 whole;
int8 b[2];
} ;
union split value;

int16 read_MAX(BYTE Shift_W)
{
long test=0x0000;//
SET_TRIS_A(0x21);  // ooio oooi
output_low(SPI_SCK);//Clock should be _low_ before the chip is selected
output_low(CS_MAX);

///////////////////////////////////////////////
//write cbyte

for (i=0;i<8;i++)
{
output_low(SPI_SCK); //--- Clock low
if(Shift_W & 0x80)
output_high(SPI_SO); //--- Bit = 1
else
output_low(SPI_SO); //--- Bit = 0
Shift_W <<= 1;
output_high(SPI_SCK); //--- Clock high
}
Output_low(SPI_SCK); //clock must be low here for best noise performance
output_high(CS_MAX);
while(!input(SSTRB)){;}      // wait for SSTRB to get high (internal conversion gets ready)
output_low(CS_MAX);
//////////////////////////////////////////////
//get the 2byte
//nop;
//delay_us(7);
for (i=0;i<16;i++)
{
//--- Clock Low, high
output_low(SPI_SCK);
output_high(SPI_SCK);
shift_left(&test,2,input(SPI_SI));//

}
output_low(SPI_SCK);
output_high(CS_MAX);
return test;
}


void main()
{

SETUP_ADC(ADC_OFF);
setup_adc_ports( NO_ANALOGS );
SET_TRIS_A(0x21);  // ooio oooi
output_low(RST_MAX);
delay_ms(100);
output_high(RST_MAX);
printf("MAX1134 interface \n\r");
delay_ms(500);


while (1) {

val=0;
//vector[0]=read_MAX(0xA5);
val=read_MAX(0xE5);
printf("MAX unipolar val=%lu   \r\n",val);
delay_ms(100);

 }
}
Ttelmah
Guest







PostPosted: Wed Jun 07, 2006 7:02 am     Reply with quote

I must admit, it looks 'right'. My initial thought was that Tcsh, might be causing a problem, with you not actually waiting for the STRB, but the tiing for this is 0nSec, so this should not be a problem. However given that 'Tconv' is 8uSec, it might be worth adding a 1uSec delay between dropping CS, and starting to read the STRB line, just in case the read is accidentally picking up the existing 'low' level at the start. I notice that 'CS', 'is not required to stay low'. Though it does not say (or show) it rising after the first bit is clocked it, it might be worth seeing what the effect of raising this is!.

Best Wishes
vibrasys



Joined: 20 Nov 2005
Posts: 16
Location: the Netherlands

View user's profile Send private message

PostPosted: Wed Jun 07, 2006 7:28 am     Reply with quote

Ttelmah wrote:
I must admit, it looks 'right'. My initial thought was that Tcsh, might be causing a problem, with you not actually waiting for the STRB, but the tiing for this is 0nSec, so this should not be a problem. However given that 'Tconv' is 8uSec, it might be worth adding a 1uSec delay between dropping CS, and starting to read the STRB line, just in case the read is accidentally picking up the existing 'low' level at the start. I notice that 'CS', 'is not required to stay low'. Though it does not say (or show) it rising after the first bit is clocked it, it might be worth seeing what the effect of raising this is!.

Best Wishes


Hi Ttelmah,
Long time no see,huh? Smile
Well,i tried to add that delay there and still no effect.I even tried to leave the CS pin high after the detection of SSTRB.What i received was a permanent 65535.But i've seen that in fig 5 on page 11,that the CS has to go low before the first bit is clocked in.so i guess this is correct
Quote:

output_high(CS_MAX);
delay_us(1);
while(!input(SSTRB)){;} // wait for SSTRB to get high (internal conversion gets ready)
output_low(CS_MAX);
//////////////////////////////////////////////
//get the 2byte
for (i=0;i<16;i++)
{
//--- Clock Low, high
output_low(SPI_SCK);
output_high(SPI_SCK);
shift_left(&test,2,input(SPI_SI));//
}


Can't really think of any solution at this point to make this AD work.
And at the same time can't explain why the four upper bits of MSByte are coming ok.
Regards
Ttelmah
Guest







PostPosted: Wed Jun 07, 2006 9:32 am     Reply with quote

I was thinking of something like:
Code:

output_high(CS_MAX);
delay_us(1);
while(!input(SSTRB)){;} // wait for SSTRB to get high (internal conversion gets ready)
output_low(CS_MAX);
//////////////////////////////////////////////
//get the 2byte
for (i=0;i<16;i++)
{
//--- Clock Low, high
output_low(SPI_SCK);
output_high(SPI_SCK);
shift_left(&test,2,input(SPI_SI));//
output_high(CS_MAX);
}

The data sheet says that CS can rise once the first bit of the reply is clocked in, and I was wondering what the effect of this is...

I must admit, I had 'hell' trying to get another Maxim IC to work. They even had demo C code, and in fact this would not work. It turned out that the data sheet itself was faulty, and one bit did not respond as they claimed. I posted a question here at the time...
It might be worth reading the data sheet for the 1132. I seem to remember they were doing a 'demo' board for this, and therefore included an assembler listing for this. The data format looks very similar, and if something is radically different in what they do for this, it might give a pointer to what is going on.
I call the process you are now undergoing "wall, head, impact technology testing"...

Best Wishes
vibrasys



Joined: 20 Nov 2005
Posts: 16
Location: the Netherlands

View user's profile Send private message

PostPosted: Wed Jun 07, 2006 10:28 am     Reply with quote

Ttelmah wrote:
The data sheet says that CS can rise once the first bit of the reply is clocked in, and I was wondering what the effect of this is...


Well,i read 65535 when i connect Ain to +3.3v;when there's lower voltages connected it prints 0.
By the way,did i mention it that it works(prints),when i connect the 1,2,or 3 batteries at Ain,even if i put delay_us(400) and even delay_ms(140) -which is HUGE,before the SSTRB check.like this
Quote:
output_high(CS_MAX);
delay_us(400);//or delay_ms(140)
while(!input(SSTRB)){;} // wait for SSTRB to get high (internal conversion gets ready)
output_low(CS_MAX);


I'll bounce my head against the wall according to your impact scheme one or two more days with this and after that i'll throw it to the garbage can Mad

Best Regards
Ttelmah
Guest







PostPosted: Wed Jun 07, 2006 10:51 am     Reply with quote

That is actually rather 'interesting'. It suggests that the top bit of the conversion, is actually getting propagated through all the bits, with the conversion only executing the 'one bit' while CS is low...
Try this. You will need to add the storage definitions for val etc..
Code:

#define SPI_SI PIN_A0 // SPI In pin
#define SPI_SO PIN_A1 // SPI Out pin
#define SPI_SCK PIN_A2 // SPI Out Clock pin
#define CS_MAX PIN_A3
#define RST_MAX PIN_A4
#define SSTRB PIN_A5

void init(void) {
   output_high(CS_MAX);
   output_low(SPI_SCK);
   output_low(RST_MAX);
   delay_ms(1);
   output_high(RST_MAX);
}

void sendbyte(int8 val) {
   int1 bit;
   int8 count;
   output_low(CS_MAX);
   for (count=0;count<8;count++) {
     bit=shift_left(&val,1,0);
     output_bit(SPI_SO,bit);
     output_high(SPI_SCK);
     delay_cycles(1);
     output_low(SPI_SCK);
   }
}

void wait_for_stb(void) {
   output_low(CS_MAX);
   delay_cycles(1);
   while (input(SSTRB)==0) ;
}

int16 getword(void) {
   int8 count;
   int16 word=0;
   output_low(CS_MAX);
   for (count=0;count<16;count++) {
      shift_left(&word,2,input_bit(SPI_SI));
      output_high(SPI_SCK);
      delay_cycles(1);
      output_low(SPI_SCK);
   }
   output_high(CS_MAX);
   return word;
}

void main() {
   SETUP_ADC(ADC_OFF);
   setup_adc_ports( NO_ANALOGS );
   SET_TRIS_A(0x21); // ooio oooi
   
   init();
   printf("MAX1134 interface \n\r");
   delay_ms(500);

   while (1) {
      sendbyte(0xE5);
      wait_for_stb();
      val=getword(0xE5);
      printf("MAX unipolar val=%lu \r\n",val);
      delay_ms(100);
   }
}


Best Wishes
vibrasys



Joined: 20 Nov 2005
Posts: 16
Location: the Netherlands

View user's profile Send private message

PostPosted: Wed Jun 07, 2006 11:11 am     Reply with quote

Ttelmah wrote:
That is actually rather 'interesting'. It suggests that the top bit of the conversion, is actually getting propagated through all the bits, with the conversion only executing the 'one bit' while CS is low...
Try this. You will need to add the storage definitions for val etc..

Best Wishes


I just downloaded the code above and SAME effect,same values.
SOooooooo strange this IC.Can i ask your yaho id,if that's ok with you,maybe we'll exchange live ideas,maybe i'll be able to run this conversion afterall.My mail is vibrasysatgmaildotcom

Best Regards
Ttelmah
Guest







PostPosted: Wed Jun 07, 2006 2:19 pm     Reply with quote

I think you really need to talk to Dallas/Maxim. Look at the code for the 1132, and see if they have perhaps got similar 'demo' code for the 1135. Though it'll probably be in assembler, it is going to involve looking carefully at what they actually 'do'. It might be worth trying the 'long' sample mode instead. Basically, I wrote what I posted, directly from the actual timing diagram, so it should produce the patterns as shown. The fact that both sets of code do the same (and I must admit I cannot see anything 'wrong' with the patterns from your's), really does suggest this is a chip/data sheet fault.
Have you tried more than one chip?. If so, then you really need to be talking to Maxim.
roger at ttelmah dot demon dot co dot uk for direct email.

Best Wishes
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