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 CCS Technical Support

Sampling rate or reference voltage help!!!

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



Joined: 15 Nov 2005
Posts: 2

View user's profile Send private message Visit poster's website AIM Address

Sampling rate or reference voltage help!!!
PostPosted: Fri Dec 09, 2005 12:10 pm     Reply with quote

I am using a PIC18F6722 to read an analog signal over the ATD and then write the value to a flash card. My problem falls when I write to the card. I have done extensive hardware testing and have found the signal is reaching the ATD correctly, but the value being written to the card is not what I expect it to be. My thoughts are that the voltage reference value is set incorrectly, or that the sampling rate and/or resolution of the ATD are not set correct. I have set the reference voltage to a value that I assume it the lowest it will go, but it seems to be only taking a few points within that range, so that leads me to believe that sampling rate/resolution is not set correct. My output for my ATD is around 0.1 to 0.8 Volts. Any help would be greatly appreciated. Question
Following is a sample of my code I am using to initialize my ATD.

main.c:
Code:
void init_devices(void)
{
  #ifdef _PIC18Fxx20_
   setup_comparator(NC_NC_NC_NC);
        Set_Tris_C(0b10111010);
   Set_Tris_D(0b00000000);
   Set_Tris_E(0b00000000);
   portE = 0b00000000;
        setup_adc(ADC_CLOCK_DIV_4|ADC_TAD_MUL_2);
        setup_adc_ports(AN0_TO_AN3|VSS_VREF);
        setup_psp(PSP_DISABLED);
        setup_wdt(WDT_OFF);
   setup_spi(SPI_MASTER|SPI_L_TO_H|SPI_CLK_DIV_4);
        setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
        setup_timer_1(T1_INTERNAL|T1_DIV_BY_4);
        setup_timer_2(T2_DIV_BY_4,69,1);
   setup_timer_3(T3_DISABLED);
   setup_timer_4(T4_DISABLED,0,1);
   setup_comparator(NC_NC_NC_NC);
   setup_vref (VREF_HIGH | 1);
        //setup_vref(VREF_LOW | 1);
        setup_low_volt_detect(FALSE);
        //setup_oscillator(OSC_8MHZ);
        setup_oscillator(OSC_NORMAL|OSC_PLL_OFF);
        enable_interrupts(INT_EXT);
        enable_interrupts(GLOBAL);
  #else
   //Lets not go here
  #endif
   setup_wdt(WDT_OFF);
   SMP = 0; // input data is sampled in the middle of data
   CKP = 0; // clock idles at low level
   CKE = 1; // data is tx'ed on rising edge (with CKP=0)
}


definitions.h:
Code:
#include <18f6722.h>
#device *=16
#device ICD=TRUE
#device ADC=10
#fuses NOWDT,WDT128, HS, NOMCLR, NOPROTECT, BROWNOUT, BORV25, PUT, NOCPD, NOSTVREN, NODEBUG, NOLVP, NOWRT, NOCPB, NOEBTR, NOWRTD, NOWRTC, NOWRTB, LPT1OSC
#use delay(clock=10000000)
//#use rs232(baud=115200,xmit=PIN_C6,rcv=PIN_C7)
#use rs232(debugger)

#define _PIC18Fxx20_



#ZERO_RAM

#use fast_io(a)
//#use fast_io(b)
#use fast_io(c)
#use fast_io(d)
#use fast_io(e)
//#use fast_io(f)
#use fast_io(g)

#byte portA = 0XF80//0x1F
//#byte portB = 0XF81
#byte portC = 0XF82
#byte portD = 0XF83
#byte portE = 0XF84
#byte portF = 0XF85
#byte portG = 0XF86

#byte tris_B   = 0XF93
#bit  B2=tris_B.2
#define B2asIP B2=1
#define B2asOP B2=0

#byte RXREG1 = 0XFAE
#byte tris_C   = 0XF94

#bit SCK =tris_C.3
#bit DOUT=tris_C.5
#bit spiSCK =tris_C.3
#bit spiDOUT=tris_C.5

/// PIN Assignments //////////////////////////////
#define SSPSTAT 0x0FC7
#define SSPCON1 0x0FC6
#BIT SMP=SSPSTAT.7
#BIT CKE=SSPSTAT.6
#BIT CKP=SSPCON1.4

#define _nop delay_cycles(1)
#include <stdlib.h>


Thanks again,
CBD Confused
_________________
C. Brad Doss
"Where does the light go when you turn the switch off?"
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Dec 09, 2005 1:04 pm     Reply with quote

Write a test program that just tests the A/D problem.
Remove 90% of the code that you posted. Display
the results of the A/D conversion on a terminal window.
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