[PIC] 33fj128gp802 DAC problem

0 views
Skip to first unread message

Martin

unread,
Jan 28, 2010, 11:16:22 PM1/28/10
to Microcontroller discussion list - Public.
I am trying to ouput a sawtooth wave using the DAC in the
PIC33FJ128GP802. Monitoring with a scope I see not a sawtooth, just a
1.8V level whenever the program runs. Debug shows that the interrupt
routines are running and sending incrementing values to the DAC.
Does anyone know what I am missing in this DAC setup code?
Regards,
Martin


#include <p33fj128gp802.h>

// boot segment fuses
_FBS(RBS_NO_RAM & BSS_NO_BOOT_CODE & BSS_NO_FLASH & BWRP_WRPROTECT_OFF);
// secure segment fuses
_FSS(RSS_NO_RAM & SSS_NO_FLASH & SWRP_WRPROTECT_OFF);
// code protection fuses
_FGS(GSS_OFF & GCP_OFF & GWRP_OFF );
// internal oscillator
_FOSCSEL( FNOSC_FRC & IESO_ON);
// oscilator selection
_FOSC(POSCMD_HS & FCKSM_CSECMD & IOL1WAY_ON );
// no watchdog
_FWDT(FWDTEN_OFF);
// 8ms power on reset
_FPOR(FPWRT_PWR16);
// Debugger and ICD
_FICD( BKBUG_OFF & JTAGEN_OFF & ICS_PGD1);

void initDAC(void) {
DAC1STATbits.ROEN = 1; /* Right Channel DAC Output Enabled */
DAC1STATbits.LOEN = 1; /* Left Channel DAC Output Enabled */
DAC1STATbits.RITYPE = 0; /* Right Channel Interrupt if FIFO is not
Full */
DAC1STATbits.LITYPE = 0; /* Left Channel Interrupt if FIFO is not
Full */
DAC1CONbits.AMPON = 1; /* Amplifier enabled During Sleep and Idle
Modes */
DAC1CONbits.DACFDIV = 10; /* Divide Clock by 10 (Assumes PLL at
160MHz) */
DAC1CONbits.FORM = 0; /* Data Format is Unsigned */
DAC1DFLT = 0x0; /* Default value set to zero when FORM = 0
*/
IFS4bits.DAC1RIF = 0; /* Clear Right Channel Interrupt Flag */
IFS4bits.DAC1LIF = 0; /* Clear Left Channel Interrupt Flag */
IEC4bits.DAC1RIE = 1; /* Right Channel Interrupt Enabled */
IEC4bits.DAC1LIE = 1; /* Left Channel Interrupt Enabled */
DAC1CONbits.DACEN = 1; /* DAC1 Module Enabled */
};

void __attribute__((interrupt, no_auto_psv))_DAC1RInterrupt(void) {
static unsigned int MyDataR;
IFS4bits.DAC1RIF = 0; /* Clear Right Channel Interrupt Flag */
DAC1RDAT = MyDataR++; /* send sawtooth to DAC i*/
}

void __attribute__((interrupt, no_auto_psv))_DAC1LInterrupt(void) {
static unsigned int MyDataL;
IFS4bits.DAC1LIF = 0; /* Clear Left Channel Interrupt Flag */
DAC1LDAT = MyDataL++; /* output overflowing sawtooth */
}

int main(void) {
AD1PCFGL = 0xffff;
TRISA=0;
TRISB=0;
initDAC();
while(1) {
LATBbits.LATB5 = 1; // turn on led
LATBbits.LATB5 = 0; // turn off led
}
return 1;
}


--
http://www.piclist.com PIC/SX FAQ & list archive
View/change your membership options at
http://mailman.mit.edu/mailman/listinfo/piclist

John Temples

unread,
Jan 28, 2010, 11:45:51 PM1/28/10
to Microcontroller discussion list - Public.
You may meed to set up ACLKCON to route a suitable clock to the DAC.
And you might not be able to do a sawtooth wave, since this is an
audio DAC.

--
John W. Temples, III

ivp

unread,
Jan 29, 2010, 3:18:06 AM1/29/10
to Microcontroller discussion list - Public.
> And you might not be able to do a sawtooth wave, since this is
> an audio DAC

I don't think that's a limitation. I'm only just starting with the 33F (for
audio applications too), so can't offer a solution to Martin's problem,
but take a look at Fig 22.2 of the d/s, which shows a ramp input and
a two-phase sawtooth output. If you can set the DAC to any output
value you should be able to create any waveform

Sean Breheny

unread,
Jan 29, 2010, 11:04:16 AM1/29/10
to Microcontroller discussion list - Public.
I agree with Jinx. Although I am not familiar with this particular
DAC, most audio DAC's are only limited in the sense that they are not
very DC accurate. They have good distortion properties but any given
code value might give an output which is a fair bit off from a
fully-accurate DAC. I think it has to do with differential versus
integral non-linearity as well as gain and offset error.

Sean

Reply all
Reply to author
Forward
0 new messages