View previous topic :: View next topic |
Author |
Message |
marken1
Joined: 26 Feb 2008 Posts: 6
|
Max517 and PIC18F4550 |
Posted: Mon Jul 07, 2008 12:42 pm |
|
|
Max517 and PIC18F4550
Posted: Mon Jul 07, 2008 6:40 pm
--------------------------------------------------------------------------------
I am trying to control a D/A converter MAX517 with PIC18F4550 but no luck. I use the MAX517 driver from the PICC directory. I have read the post related to MAX517 and I2C for PIC 18F4550 from the forum but still no success so maybe somebody can give me some hints would be much appreciated.
My setup so far:
MAX517:
VDD to +5V
OUT1(REF0) to +5V
AD0 to 0V
AD1 to 0V
SDA to PIC18F4550 (RB0)
SCL to PIC18F4550 (RB1)
My main code:
Code: | #fuses HSPLL,NOWDT,NOPROTECT,NOLVP,NODEBUG,USBDIV,PLL5,CPUDIV1,VREGEN
#use delay(clock=20000000) // 20 MhZ //
#include <MAX517.c>
void main()
{
while(1)
{
output_high(PIN_D0); //LED ON
write_dac(0xFF); //DAC output 5V
delay_ms(1000); //Delay
output_low(PIN_D0); //LED OFF
write_dac(0x00); //DAC output 0V
delay_ms(1000); //Delay
}
} |
MAX517.c
Code: | #ifndef MAX517_SDA
#define MAX517_SDA PIN_B0 //PIN assignment for PIC18F4550
#define MAX517_CLK PIN_B1 //PIN assignment for PIC18F4550
#endif
#use i2c(master, sda=MAX517_SDA, scl=MAX517_CLK, FAST,force_sw,)
void write_dac(int data_byte) {
i2c_start();
i2c_write(0x58); // AD0 and AD1 are tied to ground
i2c_write(0);
i2c_write(data_byte); // Send the data to the device
i2c_stop();
} |
The problem is that the led stays ON and is connected to D0, looks like is looking at the second instruction (write_dac(0xFF)).
If I comment out the write_dac(0xFF)[/b] and write_dac(0x00), then the led is flashing ok.
What I am doing wrong ?
I am using MPLAB V8.10 and CCS C V4.038
Regards
Marken1 |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Jul 07, 2008 12:53 pm |
|
|
Post your crystal frequency. Look at the crystal on your board and
read the frequency that's printed on it. Post it. |
|
|
marken1
Joined: 26 Feb 2008 Posts: 6
|
|
Posted: Mon Jul 07, 2008 12:59 pm |
|
|
Hi PCM Programmer,
The crystal reads 20.0000M is a metal case.
Regards
Marken |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Jul 07, 2008 1:35 pm |
|
|
If you want to run at 20 MHz with a 20 MHz crystal, then you need to
use the HS fuse. Not HSPLL. Example:
Code: | #fuses HS, NOWDT, PUT, BROWNOUT, NOLVP |
|
|
|
Guest
|
|
Posted: Mon Jul 07, 2008 1:43 pm |
|
|
Hi PCM programmer,
I have made the changes for the crystal but the some behaviour.
I have three more chips MAX517 brand new and still the some.
I have try changing the pins of the PIC18F4550 to C0 and C1 like one of
the post but the some problem, the code will stop executing when I call the function "write_dac".
Any more idee ?
Regards
Marken |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Jul 07, 2008 1:56 pm |
|
|
Quote: | MAX517:
VDD to +5V
OUT1(REF0) to +5V
AD0 to 0V
AD1 to 0V
SDA to PIC18F4550 (RB0)
SCL to PIC18F4550 (RB1) |
Your list does not show a ground connection. Do you have pin 2 of the
MAX517 connected to ground ?
Do you have the pull-up resistors on the SDA and SCL pins ?
You need them. |
|
|
Guest
|
|
Posted: Mon Jul 07, 2008 1:59 pm |
|
|
I have pin 2 of the MAX517 to gnd as is pin 5 and pin 6.
I have two pull up resistors of 4k7 on SCL and SDA pins.
Regards
Marken |
|
|
marken1
Joined: 26 Feb 2008 Posts: 6
|
|
Posted: Mon Jul 07, 2008 2:22 pm |
|
|
I got it working very happy moment.
I have copy the code from MAX517.c into the main and it works fine.
It looks like CCS does't like to call functions from and include file or it can and I have made a mistake somewhere do not know.
This is the final code.
#include <18f4550.h> // device selection
#device adc=10
#fuses HS, NOWDT, PUT, BROWNOUT, NOLVP
#use delay(clock=20000000) // 20 MhZ //
//#include <MAX517.c>
#ifndef MAX517_SDA
#define MAX517_SDA PIN_B0 //PIN assignment for PIC18F4550
#define MAX517_CLK PIN_B1 //PIN assignment for PIC18F4550
#endif
#use i2c(master, sda=MAX517_SDA, scl=MAX517_CLK, FAST,force_sw,)
void write_dac(int data_byte) {
i2c_start();
i2c_write(0x58); // AD0 and AD1 are tied to ground
i2c_write(0);
i2c_write(data_byte); // Send the data to the device
i2c_stop();
}
void main()
{
while(1)
{
output_high(PIN_D0); //LED ON
write_dac(0xFF); //DAC output 5V
delay_ms(1000); //Delay
output_low(PIN_D0); //LED OFF
write_dac(0x00); //DAC output 0V
delay_ms(1000); //Delay
}
}
Thanks for all your help PCM programmer, very kind of you.
Best regards
Marken |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Jul 07, 2008 2:25 pm |
|
|
The code will lock-up at the write_dac() line if there are no pull-up
resistors. Do you actually have the resistors connected to +5v ?
Are they really 4.7K ? Are you sure they are connected in "pull-up"
configuration and not accidently put in series with the signal lines ?
Are you sure that SDA and SCL are not accidently swapped ?
Somewhere, there is probably a hardware error. |
|
|
|