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

MAX186

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








MAX186
PostPosted: Thu Oct 26, 2006 9:28 pm     Reply with quote

Does anybody have some code for the MAX186? Thanks
Guest








PostPosted: Fri Oct 27, 2006 1:26 am     Reply with quote

I found an example code but this is isnt for CCS.
Probably the main thing is, I don't understand how to output and receive a byte to the MAX chip.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Oct 27, 2006 1:54 am     Reply with quote

Use the setup_spi() function to setup the SPI module. The MAX186
chip uses SPI mode 0. Then use spi_write() and spi_read() to
talk to the MAX186. See my post in this thread for an example
program. You will have to modify the protocol (commands and
sequence of read and write operations) to follow the examples given
in the MAX186 data sheet.
http://www.ccsinfo.com/forum/viewtopic.php?t=27833
Guest








PostPosted: Sat Oct 28, 2006 10:00 pm     Reply with quote

Alright well I think I will pass up on this for now.

I know the basics of C, but not much more so I was hoping to find someone with an existing function/header.
Guest








PostPosted: Wed Nov 01, 2006 1:53 pm     Reply with quote

Alright well I read the datasheet and the link as best as I could but I'm sure I'm missing something?

Code:

#include <16F917.h>
#fuses INTRC,NOPROTECT,NOMCLR,NOWDT,PUT
#use delay(internal=8M)
#use rs232(baud=9600, xmit=PIN_B4, rcv=PIN_B5, DISABLE_INTS)

// SPI modes.
#define SPI_MODE_0_0 0x4000
#define SPI_MODE_0_1 0x0000
#define SPI_MODE_1_0 0x0010
#define SPI_MODE_1_1 0x4010

//#define DIN  PIN_C7   // Self test pin
#define CS  PIN_D2   // Chip select pin
//#DEFINE SCLK   PIN_C6

#include <STDLIB>

//=================================
void main()
{
int8 lsb;
int8 msb;
int16 result;

output_high(CS);

setup_spi(SPI_MASTER | SPI_MODE_0_0 | SPI_CLK_DIV_64);

while(1)
  {

   output_low(CS); //2
   spi_write(0b10001110);  //3
   msb = spi_read(0x00);  //4
   lsb = spi_read(0x00);  //5
   output_high(CS);  // 6
   result = make16(msb, lsb);

   printf("%lx\n\r", result);
   delay_ms(1000);
  }

}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Nov 01, 2006 2:11 pm     Reply with quote

Look at Figure 9 in the data sheet.
http://pdfserv.maxim-ic.com/en/ds/MAX186-MAX188.pdf
It shows a conversion time of 10 us (max) after issuing the command.
You need to add "delay_us(10);" after your spi_write() statement.

Quote:
#use delay(internal=8M)

Does this syntax work ? It's not in the manual, even the vs. 4 manual.
I assume it must be in the help file for vs. 4. Just a thought, but if your
program doesn't work, try reverting to vs. 3.249 and see if it works.
Guest








PostPosted: Wed Nov 01, 2006 3:01 pm     Reply with quote

Ok well I am receiving data, but how do I read it? I'm feeding 1.17v to CH0 (selected channel) and I get 26a8 when connected and 0000 when not connected.

Yes the internal=8M syntax works, it is in the help file.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Nov 01, 2006 3:36 pm     Reply with quote

Figure 9 in the data sheet shows that you should shift the received SPI
data 3 bits to the right, to get the correct result. Add the code shown in
bold below.
Quote:

result = make16(msb, lsb);
result >>= 3;
printf("%lx\n\r", result);

For a Vref of 4.096v, the result looks to be a little bit off.
What is your Vref ? Are you using the internal Vref or an external Vref ?
Guest








PostPosted: Wed Nov 01, 2006 4:29 pm     Reply with quote

Ok well now it reads 04e3.

I'm using the internal vref.

It looks about right.. when I put my multimeter on, it reads 1176mV and at the same time the output of the MAX186 is about 11XX mV
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Nov 01, 2006 4:42 pm     Reply with quote

0x4E3 is 1251 decimal.
So to me, there's still something not quite right.

On page 13 of the MAX186 data sheet, in the lower right corner,
it talks about "compensation". Because you're using an internal
clock for the MAX186, you have to use external compensation.

This means that the \SHDN pin must be left floating, and that you
must put a 4.7 uF capacitor between the Vref pin and ground.
Guest








PostPosted: Wed Nov 01, 2006 4:57 pm     Reply with quote

From doing that, I get 04e9 which didn't make much of a difference.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Nov 01, 2006 5:05 pm     Reply with quote

What's the output impedance of the device that's providing the 1.176v
input to the MAX186 ?
The data sheet says that if the impedance is greater than 5K, then you
should put a .01 uF capacitor between the input pin of the MAX186 and
ground. (By the 'input pin', they mean whatever channel you're using).

I would try adding the capacitor. See if it helps.
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