Orcino
Joined: 07 Sep 2003 Posts: 56
|
ADC 30F2020 |
Posted: Thu May 07, 2009 8:20 am |
|
|
Hi, in code below the ADC not work in terminal show 62950.
can someone help?
Thanks
Orcino
Code: |
#include <30F2020.h>
#device ADC=10
#device *=16
#FUSES NOWDT //No Watch Dog Timer
#FUSES NOWRTB //Boot block not write protected
#FUSES NOCPB //No Boot Block code protection
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOWRT //Program memory not write protected
#FUSES FRC_PLL //Internal Fast RC oscillator with PLL
#FUSES NOCKSFSM //Clock Switching is disabled, fail Safe clock monitor is disabled
#FUSES FRANGE_HIGH
#FUSES NOOSCIO //OSC2 is clock output
#FUSES NOPR //Pimary oscillaotr disabled
#FUSES NOWINDIS //Watch Dog Timer in Window mode
#FUSES WPRES128 //Watch Dog Timer PreScalar 1:128
#FUSES WPOSTS16 //Watch Dog Timer PostScalar 1:32768
#FUSES PUT128 //Power On Reset Timer value 128ms
#FUSES NODEBUG //No Debug mode for ICD
//#FUSES ICSP1 //ICD uses PGC1/PGD1 pins
#use delay(clock=30Mhz)
#use rs232(UART1,baud=9600,parity=N,bits=8)
//******************************************************************************
// ConfiguraĆ§Ć£o de alguns REGISTROS
//******************************************************************************
int16 IOCON1, IOCON2, DUTY_PWM1, DUTY_PWM2,
D_TIME1, D_TIME2;
//******************** Registros do canal PWM1 *********************************
#locate IOCON1 = 0x40A
#bit IOCON1_PENH = 0X40A.15
#bit IOCON1_PENL = 0X40A.14
#bit IOCON1_POLH = 0X40A.13
#bit IOCON1_POLL = 0X40A.12
#bit IOCON1_PMOD1= 0X40A.11
#bit IOCON1_PMOD0= 0X40A.10
#bit IOCON1_OVERENH= 0X40A.9
#bit IOCON1_OVERENL= 0X40A.8
#bit IOCON1_OVRDAT1= 0X40A.7
#bit IOCON1_OVRDAT0= 0X40A.6
#bit IOCON1_FLTDAT1= 0X40A.5
#bit IOCON1_FLTDAT0= 0X40A.4
#bit IOCON1_CLDAT1= 0X40A.3
#bit IOCON1_CLDAT0= 0X40A.2
#bit IOCON1_0SYNC= 0X40A.0
#locate DUTY_PWM1 = 0X40E // DUTY CYCLE canal 1
//#byte PHASE1 =0X410 // FASE canal 1
//#byte D_TIME1 = 0X412 // DEAD TIME canal 1
//#byte ALTDTR1=0X414
//#byte PWMCON1 = 0X408
//#bit PWMCOM1_IUE =0X408.0 // Atualiza DUTY instantaneamente
//**************** Registros do canal PWM2 *************************************
#locate IOCON2 = 0x041E
#bit IOCON2_PENH = 0X41E.15
#bit IOCON2_PENL = 0X41E.14
#bit IOCON2_POLH = 0X41E.13
#bit IOCON2_POLL = 0X41E.12
#bit IOCON2_PMOD1= 0X413.11
#bit IOCON2_PMOD0= 0X41E.10
#bit IOCON2_OVERENH=0X41E.9
#bit IOCON2_OVERENL=0X41E.8
#bit IOCON2_OVRDAT1=0X41E.7
#bit IOCON2_OVRDAT0=0X41E.6
#bit IOCON2_FLTDAT1=0X41E.5
#bit IOCON2_FLTDAT0=0X41E.4
#bit IOCON2_CLDAT1= 0X41E.3
#bit IOCON2_CLDAT0= 0X41E.2
#bit IOCON2_0SYNC= 0X41E.0
#locate DUTY_PWM2 = 0X422 // DUTY CYCLE canal 2
#byte PHASE2 =0X424 // FASE canal 2
#locate D_TIME2 = 0X426 // DEAD TIME canal 2
//#byte ALTDTR2=0X428
//#byte PWMCON1 = 0X41C
#bit PWMCOM1_IUE =0X41C.0 // Atualiza DUTY instantaneamente
//******************************************************************************
int16 teste=1;
unsigned int16 volts=0;
void main(void)
{
SETUP_ADC_PORTS(sAN0|VSS_VDD);
SETUP_ADC(ADC_CLOCK_DIV_16|ADC_TAD_MUL_16);
SET_ADC_CHANNEL(0);
delay_us(30);
while(1)
{
volts=read_adc(ADC_START_AND_READ);
delay_us(30);
printf(" Volts = %lu \n\r ",volts);
delay_ms(300);
}
}
|
|
|