CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

DAC help!

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
gbie



Joined: 22 Apr 2009
Posts: 8

View user's profile Send private message

DAC help!
PostPosted: Thu Apr 30, 2009 1:17 am     Reply with quote

Trying to get my DAC0800 working with my pic16f886 so that I can output audio. I use a function generator to input a sine wave into the ADC and then output it to the DAC. It looks great up until about 800Hz and then it starts looking really choppy and then a little higher frequencies it can't follow the input. Any ideas what I could be doing wrong?

I tried adding a latch with A1 being the switchy thing, but that didn't help much. So I'm guessing I didn't need to do that. It doesn't work without that.
Code:

#include <16F886.h>

#fuses intrc, NOLVP, WDT, PUT, NOPROTECT

#byte ADCON0 = 0x1F                         //00000011
#byte ADCON1= 0x0                     //left justified Vss, Vdd references

#DEVICE ADC=8                        //returns MSByte
#use delay(clock=1000000)               //1MHz
#byte TRISA = 0x85
#byte PORTA = 0x5
#byte TRISB = 0x86
#byte PORTB = 0x06

//void dac_set(unsigned int dacval);
//void dac_setup(void);

void main() {
    int Ch_An_0;
    int negative_CHA0;
    TRISB =0x00;
    //    setup_vref(VREF_LOW | 6);
    setup_adc_ports( sAN0 |sAN1 | sAN5 | VSS_VDD );
    setup_adc( ADC_CLOCK_DIV_2 );
    set_adc_channel( 0 );      // ADC0 (RA0)
    while(1){
        output_low(PIN_A1);
        Ch_An_0    = read_adc();

        output_b(Ch_An_0);
        output_high(PIN_A1); //latch
        delay_us(15);
    }

}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Apr 30, 2009 1:38 am     Reply with quote

Your oscillator frequency of 1 MHz is the limiting factor. Increase it.
Also the 15us delay will slow down the sampling rate. Reduce it.

Also, you have the Watchdog enabled but you're not clearing it.
Change it to NOWDT. You don't need it during development.

Your address of 0x0 for ADCON1 is not correct.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group