View previous topic :: View next topic |
Author |
Message |
Guest
|
MAX186 |
Posted: Thu Oct 26, 2006 9:28 pm |
|
|
Does anybody have some code for the MAX186? Thanks |
|
|
Guest
|
|
Posted: Fri Oct 27, 2006 1:26 am |
|
|
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
|
|
Posted: Fri Oct 27, 2006 1:54 am |
|
|
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
|
|
Posted: Sat Oct 28, 2006 10:00 pm |
|
|
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
|
|
Posted: Wed Nov 01, 2006 1:53 pm |
|
|
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
|
|
Posted: Wed Nov 01, 2006 2:11 pm |
|
|
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
|
|
Posted: Wed Nov 01, 2006 3:01 pm |
|
|
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
|
|
Posted: Wed Nov 01, 2006 3:36 pm |
|
|
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
|
|
Posted: Wed Nov 01, 2006 4:29 pm |
|
|
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
|
|
Posted: Wed Nov 01, 2006 4:42 pm |
|
|
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
|
|
Posted: Wed Nov 01, 2006 4:57 pm |
|
|
From doing that, I get 04e9 which didn't make much of a difference. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Nov 01, 2006 5:05 pm |
|
|
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. |
|
|
|