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 CCS Technical Support

Set ADC dspic30F4011

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



Joined: 06 Dec 2011
Posts: 1

View user's profile Send private message

Set ADC dspic30F4011
PostPosted: Tue Dec 06, 2011 11:41 pm     Reply with quote

Hello, good day. I'm new here and I have a question regarding a project I'm doing with the dsPIC30F4011.
At the moment I'm just testing an ADC to adjust from 0 to 3ms PWM and ADC reading is displayed on an LCD, but reading the ADC always
is changing even if the pot is immobile and do not know what the problem is.
It is configured for the maximum sampling rate and the minimum Tad respecting datasheet and everything else but maybe something is missing AAAAAAAAAAA hehe.

Another question I have is that if use a crystal of 4M and #fuses XTPLL16 in # use delay (clock = ??) 4M or 64M

Thanks

Code:
#include <30F4011.h>           //EJEMPLO PWM
#device adc=10
#include <math.h>

#FUSES XT_PLL16   //XT Crystal Oscillator mode with 16X PLL
#FUSES PR   //Primary Oscillator
#FUSES NOPUT                    //No Power Up Timer
#FUSES NOBROWNOUT               //No brownout reset
#FUSES NOPROTECT   //Code not protected from reading
#FUSES NOWDT   //No Watch Dog Timer
#FUSES MCLR  // Master Clear pin enabled

#use delay(clock=4000000)

#define LCD_ENABLE_PIN  PIN_D0                                    ////
#define LCD_RS_PIN      PIN_D2                                    ////
#define LCD_RW_PIN      PIN_D3                                    ////
#define LCD_DATA4       PIN_F1                                    ////
#define LCD_DATA5       PIN_F4                                    ////
#define LCD_DATA6       PIN_F5                                    ////
#define LCD_DATA7       PIN_F6

#include <lcd.c>

#define ADC_CLOCK_INTERNAL 0x0184

int16 p1;
float a;
unsigned int16 duty;

void main()
{
   
setup_timer1(TMR_DISABLED);
setup_timer2(TMR_INTERNAL | TMR_DIV_BY_8,0xABDF); //periodo de 22ms para servos
setup_compare(2, COMPARE_PWM | COMPARE_TIMER2);
setup_adc_ports(sAN0|VSS_VDD);
setup_adc(ADC_CLOCK_INTERNAL);
#asm
mov #0x80E4,w4;
mov w4,0x02A0;
mov #0x0100,w4;
mov w4,0x02A2;
#endasm       
;
setup_spi(FALSE);

//set_tris_B(0x01);
set_tris_D(0x00);
set_tris_F(0x00);

lcd_init();
int i=0;

set_adc_channel(0); // pot 1K
delay_us(10);
while(i==0){

p1=read_adc();
a= (93.75 * p1 / 1023.0);
duty=a * (int16)64;

set_pwm_duty(2,duty);   

lcd_gotoxy(1,1);
printf(lcd_putc,"p1=%4ld",p1); // u,4ld,f
lcd_gotoxy(1,2);
printf(lcd_putc,"duty ms=%4ld",duty);

delay_ms(1);

}
}

_________________
Regards
Luis
cloudff7



Joined: 23 Jun 2015
Posts: 1
Location: MEXICO

View user's profile Send private message

PostPosted: Tue Jun 23, 2015 1:54 pm     Reply with quote

HOLA,

ME PARECE QUE HABLAS ESPAÑOL (O POR LO MENOS ES LO QUE NOTO EN PARTE DE TU PROGRAMA)

SI TE REFIERES A QUE LA LCD SE RESETEA AUNQUE EL POTENCIOMETRO NO SE ESTE MOVIENDO, LA PROBLEMA ESTA EL LA ALIMENTACION, EL SERVOMOTOR CONSUME ALGO DE CORRIENTE AL IGUAL QUE LA LCD POR LO QUE TIENDE A APAGAR Y PRENDERSE A CADA RATO,TE SUGIERO QUE LOS ALIMENTES POR SEPARADO, PARA ELIMINAR EL PROBLEMA.

TAMBIEN ME GUSTARIA CONTACTARTE YA QUE QUISIERA APRENDER A MANEJAR SERVOS CON EL 30F4011 PERO TENGO POCA INFORMACION ALA MANO.

SALUDOS
_________________
MICROCONTROLLERS
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