nitin.joshi52@gmail.com
Newbie level 5
- Joined
- Mar 30, 2013
- Messages
- 10
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,281
- Activity points
- 1,396
Gm SIR,
my name is nitin joshi.i am very much new on microchip.
I want to write code for a to d converter ie want to take two analog input ie first one is sine wave(voltage) and another one is an offset voltage.
i am using dsPIC33fj64mc802 IC and writing code in xc 16 compiler.
in this there are 6 analog inputs are given.i want to select two analog input.ie AN0 and AN1.four channels are available and i want to select channel CH1 and CH2 for AN0 and AN1.
right now i am using general data sheet for dspic33 section 16 analog to digital converter and reference manual for dsPIC33.i want specific data sheet to configure a to d for dspic33fj64mc802.
here i am attaching the code also which i have already written.
but this is not working.
also I want to read 2 adc value but I don't know how to read 2 adc value because in the datasheet only one adc buffer is available.
how to write this delay function also because this library delay is not working.
please help .i am very much new may be i forgot to give you some more information.
thanks in advance
here is my code .......
#include<xc.h>
#include<delay.h>
#include<time.h>
#include<p33FJ64MC802.h>
#include<stdint.h>
int ADCValue;
void initAdc1(void)
{
AD1CON1bits.AD12B = 0; // select 10-bit ADC operation
AD1CON2bits.VCFG=0;//Converter Voltage Reference Configuration bits(Avdd & Avss)
AD1CON3bits.ADRC = 0; // ADC Clock is derived from Systems Clock
AD1CON3bits.SAMC = 0; // Auto Sample Time = 0 * TAD
AD1CON3bits.ADCS = 2; // ADC Conversion Clock TAD = TCY * (ADCS + 1) = (1/40M) * 3 =
// 75 ns (13.3 MHz)
// ADC Conversion Time for 10-bit Tconv = 12 * TAD = 900 ns (1.1 MHz)
AD1CON2bits.ALTS =0;//Always uses channel input selects for Sample A
AD1PCFGL = 0xFFFC;//AN0 and AN1 are selected as analog input pins......
//AD1PCFGLbits.PCFG0 = 0; // AN0 as Analog Input
AD1CHS123bits.CH123SA = 0; // CH1 positive input is AN0, CH2 positive input is AN1
AD1CHS123bits.CH123NA = 0; //CH1, CH2, CH3 negative input is VREF-(vss)
AD1CON2bits.CHPS = 3; // Converts channels CH1/CH2
AD1CON1bits.SIMSAM=1; //Samples CH1, CH2 simultaneously
AD1CON1bits.SSRC = 7; // Internal Counter (SAMC) ends sampling and starts conversion
AD1CON1bits.ASAM = 1; // ADC Sample Control: Sampling begins immediately after conversion
AD1CON1bits.FORM = 3; // Data Output Format: Signed Fraction (Q15 format)
AD1CON1bits.ADON = 1; // Turn on the ADC
}
int ADCread(void)
{
AD1PCFGLbits.PCFG0 = 0; // AN0 as Analog Input
IFS0bits.AD1IF = 0; // Clear the Analog-to-Digital interrupt flag bit
IEC0bits.AD1IE = 0; // Do Not Enable Analog-to-Digital interrupt
AD1CON1bits.ADON = 1; // Turn on the ADC
AD1CON1bits.SAMP = 1; // Start sampling
//DelayUs(10); // Wait for sampling time (10us)
AD1CON1bits.SAMP = 0; // Start the conversion
while (!AD1CON1bits.DONE); // Wait for the conversion to complete
//ADCValue = ADC1BUF0; // Read the conversion result
}
void main()
{
initAdc1();
while(1)
{
ADCread();
ADCValue = ADC1BUF0;read the adc value
}
}
my name is nitin joshi.i am very much new on microchip.
I want to write code for a to d converter ie want to take two analog input ie first one is sine wave(voltage) and another one is an offset voltage.
i am using dsPIC33fj64mc802 IC and writing code in xc 16 compiler.
in this there are 6 analog inputs are given.i want to select two analog input.ie AN0 and AN1.four channels are available and i want to select channel CH1 and CH2 for AN0 and AN1.
right now i am using general data sheet for dspic33 section 16 analog to digital converter and reference manual for dsPIC33.i want specific data sheet to configure a to d for dspic33fj64mc802.
here i am attaching the code also which i have already written.
but this is not working.
also I want to read 2 adc value but I don't know how to read 2 adc value because in the datasheet only one adc buffer is available.
how to write this delay function also because this library delay is not working.
please help .i am very much new may be i forgot to give you some more information.
thanks in advance
here is my code .......
#include<xc.h>
#include<delay.h>
#include<time.h>
#include<p33FJ64MC802.h>
#include<stdint.h>
int ADCValue;
void initAdc1(void)
{
AD1CON1bits.AD12B = 0; // select 10-bit ADC operation
AD1CON2bits.VCFG=0;//Converter Voltage Reference Configuration bits(Avdd & Avss)
AD1CON3bits.ADRC = 0; // ADC Clock is derived from Systems Clock
AD1CON3bits.SAMC = 0; // Auto Sample Time = 0 * TAD
AD1CON3bits.ADCS = 2; // ADC Conversion Clock TAD = TCY * (ADCS + 1) = (1/40M) * 3 =
// 75 ns (13.3 MHz)
// ADC Conversion Time for 10-bit Tconv = 12 * TAD = 900 ns (1.1 MHz)
AD1CON2bits.ALTS =0;//Always uses channel input selects for Sample A
AD1PCFGL = 0xFFFC;//AN0 and AN1 are selected as analog input pins......
//AD1PCFGLbits.PCFG0 = 0; // AN0 as Analog Input
AD1CHS123bits.CH123SA = 0; // CH1 positive input is AN0, CH2 positive input is AN1
AD1CHS123bits.CH123NA = 0; //CH1, CH2, CH3 negative input is VREF-(vss)
AD1CON2bits.CHPS = 3; // Converts channels CH1/CH2
AD1CON1bits.SIMSAM=1; //Samples CH1, CH2 simultaneously
AD1CON1bits.SSRC = 7; // Internal Counter (SAMC) ends sampling and starts conversion
AD1CON1bits.ASAM = 1; // ADC Sample Control: Sampling begins immediately after conversion
AD1CON1bits.FORM = 3; // Data Output Format: Signed Fraction (Q15 format)
AD1CON1bits.ADON = 1; // Turn on the ADC
}
int ADCread(void)
{
AD1PCFGLbits.PCFG0 = 0; // AN0 as Analog Input
IFS0bits.AD1IF = 0; // Clear the Analog-to-Digital interrupt flag bit
IEC0bits.AD1IE = 0; // Do Not Enable Analog-to-Digital interrupt
AD1CON1bits.ADON = 1; // Turn on the ADC
AD1CON1bits.SAMP = 1; // Start sampling
//DelayUs(10); // Wait for sampling time (10us)
AD1CON1bits.SAMP = 0; // Start the conversion
while (!AD1CON1bits.DONE); // Wait for the conversion to complete
//ADCValue = ADC1BUF0; // Read the conversion result
}
void main()
{
initAdc1();
while(1)
{
ADCread();
ADCValue = ADC1BUF0;read the adc value
}
}