View previous topic :: View next topic |
Author |
Message |
hemnath
Joined: 03 Oct 2012 Posts: 242 Location: chennai
|
LTC1655 with 18F2620 |
Posted: Thu Feb 09, 2017 2:40 am |
|
|
Hi, I am interacting 16 bit DAC LTC1655 with 18F2620.
Any sample code? Please help. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19589
|
|
Posted: Thu Feb 09, 2017 9:43 am |
|
|
Nothing needed.
Just connect it to the PIC SPI pins. It's DI to the PIC's DO (pin C5).
One more pin needed for CS. - choose whatever pin you want.
Then:
Code: |
#define CS_PIN PIN_xx //where this is the pin you want
#use spi(SPI1, BITS=16, ENABLE=CS_PIN, MODE=0)
//At the start of your main
output_high(CS_PIN); //ensure this starts high
//then to write a value
int16 value;
value='whatever you want';
spi_xfer(value);
|
The chip supports a maximum SPI clock rate of 10Mhz, so the default (which is to set the SPI as fast as possible), will be fine. |
|
|
hemnath
Joined: 03 Oct 2012 Posts: 242 Location: chennai
|
|
Posted: Wed Mar 15, 2017 5:39 am |
|
|
I have tested the sample program.
To test the sample code, value set as 1500. The measure output voltage from the DAC is 94mV. It shows 94mV for sometime and it changes to 0V for an instant and again it to 94mV. It goes on continuously.
Please help me to solve this issue.
Test code:
Code: | #include "18F2520.h"
#include "f2420_regs.h"
#fuses INTRC_IO
#use delay(clock=1000000)
#define CS_PIN PIN_C1 //where this is the pin you want
#use spi(SPI1, BITS=16, ENABLE=CS_PIN, MODE=0)
void main()
{
//At the start of your main
output_high(CS_PIN); //ensure this starts high
//then to write a value
int16 value;
value = 0;
while(1)
{
value = 1500;
spi_xfer(value);
// delay_ms(100);
}
} |
|
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9269 Location: Greensville,Ontario
|
|
Posted: Wed Mar 15, 2017 5:56 am |
|
|
I haven't used that DAC device but downloaded the datasheet.
In your program you don't delay between accessing the DAC, you've commented out the delay_ms(100); line
The DAC has a maximum speed of 750KHz. While I haven't done the math (you should BTW) I think your program is updating (accessing) the DAC too fast.
The DAC output seems to be close to correct. 1500/65536*4.095 +-.
I suggest putting the delay back in and see what happens.
recode/recompile/retest/report back !
Jay |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Mar 15, 2017 7:04 am |
|
|
What load do you have on the DAC's output pin ? Is it just the scope
probe, or do you have other circuits ? Describe those circuits. |
|
|
hemnath
Joined: 03 Oct 2012 Posts: 242 Location: chennai
|
|
Posted: Wed Mar 15, 2017 1:35 pm |
|
|
I have tried with 100 ms to 5000 ms delay. Sorry, while posting the code it was a typo, in commenting the delay_ms.
With the output from the DAC, I have used a buffer and designed a voltage to current source circuit. measuring the current output using keithley 8 1/2 digit multimeter. Display shows the mA value for a while, suddenly for a fraction of second it drops down and settle back again. I also disconnected my current conversion section, measured the output voltage from the DAC using the 8 1/2 multimeter. Output voltage will be 94mV for a while and suddenly drops and again settles to 94mV. It happens continuously. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9269 Location: Greensville,Ontario
|
|
Posted: Wed Mar 15, 2017 1:46 pm |
|
|
OK, I only see one fuse in your program. I would suggest you enter ALL of them and NOT rely upon the 'default' vaules someone else has chosen.
It could be that the WDT has been enabled. If so, that would reset the PIC and could be the 'odd' behaviour.
I don't use that PIC but most these days have 20-30 fuses.
Also measure the VDD to be sure it's steady..maybe the PSU is crowbarring....
Jay |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Mar 15, 2017 2:07 pm |
|
|
What happens if you disconnect all external circuits on the DAC output pin
and look at it with an oscilloscope ? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19589
|
|
Posted: Wed Mar 15, 2017 2:56 pm |
|
|
I'd second the comment about fuses.
From the description, I'd guess the PIC watchdog is enabled, and it is doing a reset. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Mar 15, 2017 3:51 pm |
|
|
I don't think so, unless he's using different code than he has posted.
In previous threads, he said he's using compiler vs. 4.114.
I installed that version and compiled his program. Here are the fuses
at the end of the .LST file. The WDT is disabled.
Quote: | Configuration Fuses:
Word 1: C800 INTRC_IO FCMEN IESO
Word 2: 1E1E PUT BROWNOUT BORV20 NOWDT WDT32768
Word 3: 8700 CCP2C1 PBADEN LPT1OSC MCLR
Word 4: 0081 STVREN NOLVP NOXINST NODEBUG
Word 5: C00F NOPROTECT NOCPB NOCPD
Word 6: E00F NOWRT NOWRTC NOWRTB NOWRTD
Word 7: 400F NOEBTR NOEBTRB
|
1. I don't trust his multimeter. He should use a scope.
2. I don't trust that his buffer and/or current conversion circuit are
done correctly. It could be that when they have a signal applied,
they load down his (high impedance) power supply and this causes
the DAC to reset. The DAC data sheet says its output will go to zero
in this case.
3. He needs to post a link to a schematic of his external circuits, and of
his power supply circuit. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9269 Location: Greensville,Ontario
|
|
Posted: Wed Mar 15, 2017 4:33 pm |
|
|
fuse might have been altered within this file
#include "f2420_regs.h"
I hate to guess at stuff but what's in there ???
hmm... brownout can reset the PIC... maybe the PSU is underrated and VDD goes below the BO threshold ??
lots of possibilites, too little info.
Jay |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19589
|
|
Posted: Thu Mar 16, 2017 12:43 am |
|
|
Totally agreed.
The regular pulsing, sounded so like a timeout interval, that my 'suspicion index' was being triggered.
|
|
|
hemnath
Joined: 03 Oct 2012 Posts: 242 Location: chennai
|
|
Posted: Thu Mar 16, 2017 10:27 pm |
|
|
Thanks for the suggestions.
I have disconnected all my external circuit. Just powered only the controller and the DAC with +5V. MCLR is +5V. No change in the supply voltage.
Compiling only this code and testing.
Code: | #include "18F2520.h"
#fuses INTRC_IO, NOWDT,BROWNOUT,PUT
#use delay(clock=1000000)
#define CS_PIN PIN_C1 //where this is the pin you want
#use spi(SPI1, BITS=16, ENABLE=CS_PIN, MODE=0)
void main()
{
//At the start of your main
output_high(CS_PIN); //ensure this starts high
//then to write a value
int16 value;
value = 0;
delay_ms(1000);
while(1)
{
output_low(CS_PIN); //ensure this starts
value = 5000;
spi_xfer(value);
delay_ms(250);
}
} |
Also measured in scope. measures 320mV and suddenly it drops and steady back to 320mV. |
|
|
jeremiah
Joined: 20 Jul 2010 Posts: 1358
|
|
Posted: Fri Mar 17, 2017 7:07 am |
|
|
Try instead:
Code: |
#include "18F2520.h"
#fuses INTRC_IO, NOWDT,BROWNOUT,PUT
#use delay(clock=1000000)
#define CS_PIN PIN_C1 //where this is the pin you want
#use spi(SPI1, BITS=16, MODE=0,stream=DAC_STREAM)
void main()
{
int16 value;
output_high(CS_PIN); //ensure this starts high
value = 5000;
delay_ms(1000); //gives chip time to power up
while(1)
{
output_low(CS_PIN);
delay_us(1); //added some hold time
spi_xfer(DAC_STREAM,value,16);
delay_us(1); //added some hold time
output_high(CS_PIN);
delay_ms(250);
}
}
|
|
|
|
hemnath
Joined: 03 Oct 2012 Posts: 242 Location: chennai
|
|
Posted: Sun Mar 19, 2017 10:02 pm |
|
|
Still it behaves the same. |
|
|
|