Autor Tema: Modulo ADC PSI  (Leído 1825 veces)

0 Usuarios y 2 Visitantes están viendo este tema.

Desconectado magusito

  • PIC10
  • *
  • Mensajes: 30
Modulo ADC PSI
« en: 13 de Abril de 2010, 00:01:29 »
Buenas, estoy con otro pequeno proyecto a ver si alguien se interesa y me echa una ayudita. Necesito Realizar un  programa que permita leer la magnitud de 3 voltajes de manera simultanea utilizando 3 canales análogos del pic.
Visualizar en un LCD a través del acceso a pines.
Los voltajes deben ser de 0 a 30 VDC

#include <18F452.h>
#device adc=10
#FUSES NOWDT                    //No Watch Dog Timer
#FUSES WDT128                   //Watch Dog Timer uses 1:128 Postscale
#FUSES XT                       //Crystal osc <= 4mhz for PCM/PCH , 3mhz to 10 mhz for PCD
#FUSES NOPROTECT                //Code not protected from reading
#FUSES NOOSCSEN                 //Oscillator switching is disabled, main oscillator is source
#FUSES NOBROWNOUT               //No brownout reset
#FUSES BORV20                   //Brownout reset at 2.0V
#FUSES PUT                      //Power Up Timer
#FUSES STVREN                   //Stack full/underflow will cause reset
#FUSES NODEBUG                  //No Debug mode for ICD
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOWRT                    //Program memory not write protected
#FUSES NOWRTD                   //Data EEPROM not write protected
#FUSES NOWRTB                   //Boot block not write protected
#FUSES NOWRTC                   //configuration not registers write protected
#FUSES NOCPD                    //No EE protection
#FUSES NOCPB                    //No Boot Block code protection
#FUSES NOEBTR                   //Memory not protected from table reads
#FUSES NOEBTRB                  //Boot block not protected from table reads
#use delay(clock=4000000)

#define LCD_RS_PIN      PIN_D0
#define LCD_RW_PIN      PIN_D1
#define LCD_ENABLE_PIN  PIN_D2
#define LCD_DATA4       PIN_C4
#define LCD_DATA5       PIN_C5
#define LCD_DATA6       PIN_C6
#define LCD_DATA7       PIN_C7
#include<lcd.c>

long   Resultado;
float   Presion;

void main()
{
   setup_adc_ports(NO_ANALOGS);
   setup_adc(ADC_CLOCK_DIV_2);
   setup_psp(PSP_DISABLED);
   setup_spi(SPI_SS_DISABLED);
   setup_wdt(WDT_OFF);
   setup_timer_0(RTCC_INTERNAL);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);

   set_tris_a(0b01111111);
   set_tris_b(0b11111111);
   set_tris_c(0b00001111);
   set_tris_d(0b11111000);
   set_tris_e(0b00000111);

   setup_adc(ADC_CLOCK_INTERNAL);
   setup_adc_ports(AN0);
   set_adc_channel(0);

   lcd_init();
   lcd_putc('\f');
   lcd_gotoxy(6,1);
   lcd_putc("Modulo ADC");
   delay_ms(1000);
   lcd_putc('\f');
   while(True)
   {
      Resultado = read_adc();

      Presion = Resultado * 0.09775;
      lcd_putc('\f');
      printf(lcd_putc,"Presion = %1.2fPSI",Presion);

      delay_ms(100);
   }
}


Esto es lo poco que llevo

Desconectado AKENAFAB

  • Colaborador
  • DsPIC30
  • *****
  • Mensajes: 3227
Re: Modulo ADC PSI
« Respuesta #1 en: 13 de Abril de 2010, 03:58:00 »
No puedes realizar la adquisicion somultanea de 3 canales ya que solo se dispone de un solo modulo conversor.Asi que primero lees canal 1-canal2 y al final canal3.

Se me ocurre que lo más cercano a tiempo real sea lo siguiente:

Adquieres canal 1 - Lo guardas
inmediatamente sigues con canal 2 lo guardas
Terminas con canal 3

Realizas las operaciones matematicas necesarias

Y ya tienes listo los 3 valores de los 3 canales para imprimir en pantalla.

El pic no puede recibir mas de 5v en sus entradas , asi que tendras que bajar ese voltaje , ya sea con un divisor de tension u otra coa que se te ocurra.

Saludos!

Desconectado magusito

  • PIC10
  • *
  • Mensajes: 30
Re: Modulo ADC PSI
« Respuesta #2 en: 23 de Abril de 2010, 12:33:24 »
Simulacion:

Desconectado magusito

  • PIC10
  • *
  • Mensajes: 30
Re: Modulo ADC PSI
« Respuesta #3 en: 05 de Mayo de 2010, 16:54:21 »
Aca les muestro la respuesta del trabajo. Ya antes habia enviado la simulacion en proteus, solo es compilar el pic con el siguiente programa y funciona.


#include <18F452.h>
#device adc=10
#FUSES NOWDT                    //No Watch Dog Timer
#FUSES WDT128                   //Watch Dog Timer uses 1:128 Postscale
#FUSES XT                       //Crystal osc <= 4mhz for PCM/PCH , 3mhz to 10 mhz for PCD
#FUSES NOPROTECT                //Code not protected from reading
#FUSES NOOSCSEN                 //Oscillator switching is disabled, main oscillator is source
#FUSES NOBROWNOUT               //No brownout reset
#FUSES BORV20                   //Brownout reset at 2.0V
#FUSES PUT                      //Power Up Timer
#FUSES STVREN                   //Stack full/underflow will cause reset
#FUSES NODEBUG                  //No Debug mode for ICD
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOWRT                    //Program memory not write protected
#FUSES NOWRTD                   //Data EEPROM not write protected
#FUSES NOWRTB                   //Boot block not write protected
#FUSES NOWRTC                   //configuration not registers write protected
#FUSES NOCPD                    //No EE protection
#FUSES NOCPB                    //No Boot Block code protection
#FUSES NOEBTR                   //Memory not protected from table reads
#FUSES NOEBTRB                  //Boot block not protected from table reads
#use delay(clock=4000000)

#define LCD_RS_PIN      PIN_D0
#define LCD_RW_PIN      PIN_D1
#define LCD_ENABLE_PIN  PIN_D2
#define LCD_DATA4       PIN_C4
#define LCD_DATA5       PIN_C5
#define LCD_DATA6       PIN_C6
#define LCD_DATA7       PIN_C7
#include<lcd.c>

long   Resultado;
float   Presion;

void main()
{
   setup_adc_ports(NO_ANALOGS);
   setup_adc(ADC_CLOCK_DIV_2);
   setup_psp(PSP_DISABLED);
   setup_spi(SPI_SS_DISABLED);
   setup_wdt(WDT_OFF);
   setup_timer_0(RTCC_INTERNAL);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);

   set_tris_a(0b01111111);
   set_tris_b(0b11111111);
   set_tris_c(0b00001111);
   set_tris_d(0b11111000);
   set_tris_e(0b00000111);

   setup_adc(ADC_CLOCK_INTERNAL);
   setup_adc_ports(AN0_AN1_AN3);
   set_adc_channel(0);

   lcd_init();
   lcd_putc('\f');
   lcd_gotoxy(4,1);
   lcd_putc("Modulo ADC");
   delay_ms(1000);
   lcd_putc('\f');

      set_adc_channel(0);
         
   while(True)
   {
      set_adc_channel(0);
      Resultado = read_adc();
      Presion = (0.029325513*Resultado);//y=mx+b      
      lcd_gotoxy(1,1);
      printf(lcd_putc,"1=%1.2fC",Presion);
      delay_ms(10);
      set_adc_channel(1);
      Resultado = read_adc();
      Presion = (0.029325513*Resultado);//y=mx+b      
      lcd_gotoxy(10,1);
      printf(lcd_putc,"2=%1.2fC",Presion);
      delay_ms(10);
      set_adc_channel(2);
      Resultado = read_adc();
      Presion = (0.029325513*Resultado);//y=mx+b      
      lcd_gotoxy(6,2);
      printf(lcd_putc,"3=%1.2fC",Presion);
      delay_ms(10);
   }
}