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

Problem with ADC +TMR3 dsPIC30F4011

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



Joined: 16 Oct 2009
Posts: 3

View user's profile Send private message

Problem with ADC +TMR3 dsPIC30F4011
PostPosted: Thu Nov 11, 2010 1:14 pm     Reply with quote

Hi,
I need you help with my code, because the ADC value converted is half of my full int (1024 @ 5V).
My code is the next one:
Main code
Code:

#include "dspic_ADC_2khz_v1.1.h"

//Includes
 #include <float.h>
 #include <math.h>
 #include <stdlib.h>
 #include <string.h>
//Asignación de bits

 #BIT FORM8=0x02A0.8 //bit 8 modo de adquisición de ADC
 #BIT FORM9=0x02A0.9 //bit 9
 #BIT ASAM=0x02A0.2  //BIT DE CONFIGURACIÓN DE AUTO INICIO DE MUESTREO
 // #BIT SIMSAM=0x02A0.3//bit 3 del registro de memoria ADCON1 para muestreo simultáneo
 // #BIT CHPS0=0x02A2.8 //bit 8-9 del registro de memoria ADCON2 para muestreo simultáneo
 // #BIT CHPS1=0x02A2.9 //de los canales CH0 y CH1
 #BIT ADIF=0x0084.11 //BANDERA DE SOLICITUD DE INTERRUPCIÓN ADC
 // #BIT ADIE=0x008C.11 //HABILITA INTERRUPCIÓN ADC
 #BIT SSRC7=0x02A0.7// COMPARADOR GP DEL TIMER 3 (BIT2)
 #BIT SSRC6=0x02A0.6// (BIT1)
 #BIT SSRC5=0x02A0.5// (BIT0)
 #BIT ADON=0x02A0.15// ARRANCA CONVERSOR ADC
 #BIT TON=0x0104.15 //ARRANCA TIMER 3
 
 #use rs232(UART1A,baud=9600,parity=N,bits=8)
 
 //variables
  int16 valor;
  float valor_conv;
 
#int_ADC1
void  ADC1_isr(void)
{
ADIF=0; // Borrar bandera solicitud interr. AD
valor=read_adc(); // Tomar valor convertido
printf("%i\r\n",valor);
}




void main()
{
   setup_spi( FALSE );

   setup_adc_ports(sAN0 | sAN1 | sAN2 | VSS_VDD);

   setup_timer2(TMR_DISABLED |TMR_DIV_BY_1 ,0);
   setup_timer4(TMR_DISABLED |TMR_DIV_BY_1 ,0);
   setup_timer3(TMR_INTERNAL |TMR_DIV_BY_8 ,12);
   setup_timer5(TMR_DISABLED |TMR_DIV_BY_1 ,0);
  // set_timer3(0x000);
   setup_wdt(WDT_OFF);
   setup_timer1(TMR_DISABLED);
   enable_interrupts(INTR_GLOBAL);
   SSRC7=0; // T3 inicia conversion
   SSRC6=1;
   SSRC5=0;
   FORM8=0;
   FORM9=0;
   ASAM=1; // Inicia muestreo en fin de conversion
   set_adc_channel(0); // Muestrea canal AN0
   

   // Configurar interr., arrancar T3 y AD
   ADIF=0; // Borrar bandera solicitud interr. AD
   enable_interrupts(INT_ADC1);
   ADON=1; // Arrancar conversor AD
   TON=1; // Poner T3 en marcha
   while(1)
{
}
}


[b]dspic_ADC_2khz_v1.1.h[/b]

#include<30F4011.h>
#device ADC=10

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES XT_PLL8                  //XT Crystal Oscillator mode with 8X PLL
#FUSES PR                       //Primary Oscillator
#FUSES NOCKSFSM                 //Clock Switching is disabled, fail Safe clock monitor is disabled
#FUSES WPSB16                   //Watch Dog Timer PreScalar B 1:16
#FUSES WPSA512                  //Watch Dog Timer PreScalar A 1:512
#FUSES PUT64                    //Power On Reset Timer value 64ms
#FUSES NOBROWNOUT               //No brownout reset
#FUSES BORRES               
#FUSES LPOL_HIGH                //Low-Side Transistors Polarity is Active-High (PWM 0,2,4 and 6)
   //PWM module low side output pins have active high output polar
#FUSES HPOL_HIGH                //High-Side Transistors Polarity is Active-High (PWM 1,3,5 and 7)
   //PWM module high side output pins have active high output polarity
#FUSES NOPWMPIN                 //PWM outputs drive active state upon Reset
#FUSES MCLR                     //Master Clear pin enabled
#FUSES NOPROTECT                //Code not protected from reading
#FUSES NOWRT                    //Program memory not write protected
#FUSES NODEBUG                  //No Debug mode for ICD
#FUSES NOCOE                    //Device will reset into operational mode
#FUSES ICSP1                    //ICD uses PGC1/PGD1 pins

#use delay(clock=96000000)

If you can help me, very thank!!
Version ccs 4.107
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