cbraddoss
Joined: 15 Nov 2005 Posts: 2
|
Sampling rate or reference voltage help!!! |
Posted: Fri Dec 09, 2005 12:10 pm |
|
|
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.
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 _________________ C. Brad Doss
"Where does the light go when you turn the switch off?" |
|