Hi all,
I'm new in micro-controller and now i'm working in dspic30f6014a for a imaging project. I found out this forum very useful and hope I could learn and share in terms of technical and programming as much as possible among experienced members. I have little experience in assembly language however not in c language. So forgive me if some of terms I used sometimes are not appropriate. Currently I have a project which require me to understand the C language programming. In the project I need to read surface potential from 16 sensors each of them is connected to ADC (AN0 to AN15) at portB. I searched various examples in ADC particularly for dspic30f. For the beginning, I tried to understand the programs and modified here and there to suits for my applications. To reduce the complexity of the program, I modify the program to read only from 2 analog inputs (RB0/AN0 and RB1/AN1). For my first C program the objective is to read the analog signals then digitized it and store in respective buffer (ADCBUF0 & ADCBUF1) before send it via UART1. I'm using pickit2, MPLAB ver8.92 , C30 compiler and 20 MHz oscillator. However when I build the program, unfortunately it failed. Please advice.
Thank you in advance.
//modified form original program: http://www.mikroe.com/chapters/view/55/ ... converter/
#include<p30f6014a.h>
#define FCY29480000UL
#include<libpic30.h>
#include<adc12.h>
#include<stdio.h>
#include<delay.h>
int ADCvalue0;
int ADCvalue1;
_FWDT(WDT_OFF); // off watch-dog timer -bit configuration
_FOSC(CSW_FSCM_OFF & HS); //clock switching, fail safe monitor disable, high-speed osc
_FBORPOR(PBOR_ON & BORV_27 & MCLR_EN);
_FGS(CODE_PROT_OFF); //code protection-off
int main()
{
ADCON1bits.ADON = 0; //turn ADC OFF
ADCON1bits.ADON = 0; // turn ADC OFF before initialization
ADCON2bits.BUFM = 0; // Buffer configured as one 16-word
ADCON2bits.ALTS = 0; // Always use MUX A input multiplexer
ADCON2bits.SMPI = 0; // Int. at the completion of conversion for each sample/convert sequence.
ADCON1bits.ADON = 1; // turn ADC ON
TRISB = 0xFFFF; //Port B is input
ADPCFG = 0xFFFA; //channel AN0 and AN1 (analog) is sampled and converted
//ADCON1 = 0x0040; //ADC off, output_format=INTEGER
//Timer 3 starts convesion
ADCHS = 0x0003; //Connect RB0 on AN0 and RB1 on AN1 as inputs
ADCSSL = 0; //No scan
ADCON3 = 0x0F00; //TAD = internalTCY
//Sample time ends with timer 3 clock
/*TIMER3 init*/
TMR3 = 0; //Reset TIMER3 counter
PR3 = 0x3FFF; //PR3, number of TIMER3 clocks between two conversions start
T3CON = 0x8010; //TIMER3 ON, prescale 1:1
while(1)
{
// Channel AN0
ADCHSbits.CH0SA = 0b0000;
ADCON1bits.SAMP = 1; // start sampling ...
__delay_us(10);
while
(!ADCON1bits.DONE); // conversion done?
__delay_us(10);
ADCvalue0 = ADCBUF0;
//mCsend16adc(); //load buffer and transmit
// Channel AN1
ADCHSbits.CH0SA = 0b0001;
ADCON1bits.SAMP = 1; // start sampling ...
__delay_us(10);
while
(!ADCON1bits.DONE); // conversion done?
__delay_us(10);
ADCvalue1 = ADCBUF1;
//mCsend16adc();
}
}