#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 W. Temples, III
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