|
|
View previous topic :: View next topic |
Author |
Message |
borre4
Joined: 06 Dec 2011 Posts: 1
|
Set ADC dspic30F4011 |
Posted: Tue Dec 06, 2011 11:41 pm |
|
|
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
|
|
Posted: Tue Jun 23, 2015 1:54 pm |
|
|
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 |
|
|
|
|
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
|