Electgpl

PIC - Medición TrueRMS v3

Jun 6th, 2016
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.54 KB | None | 0 0
  1. #include <16F883.h>
  2. #device adc=10
  3. #use delay(int=4000000)
  4. #define LCD_ENABLE_PIN  PIN_B2
  5. #define LCD_RS_PIN      PIN_B0
  6. #define LCD_RW_PIN      PIN_B1
  7. #define LCD_DATA4       PIN_B4
  8. #define LCD_DATA5       PIN_B5
  9. #define LCD_DATA6       PIN_B6
  10. #define LCD_DATA7       PIN_B7
  11. #include <LCD.C>
  12. #include <math.h>
  13. void main(){
  14.    setup_adc_ports(sAN0|sAN1|VREF_VREF);
  15.    setup_adc(ADC_CLOCK_DIV_2);
  16.    int16 i;
  17.    float adc1, valorMax1=0, adc2, valorMax2=0;
  18.    float tension, corriente, potencia;
  19.    lcd_init();
  20.    lcd_gotoxy(1,1);
  21.    printf(lcd_putc,"   PowerMeter   ");
  22.    lcd_gotoxy(1,2);
  23.    printf(lcd_putc," TrueRMS   v1.3 ");
  24.    delay_ms(1000);
  25.    lcd_init();
  26.    while(true){
  27.       do{
  28.          set_adc_channel(0);
  29.          adc1=read_adc()*3.5/1023.0;
  30.          delay_us(20);
  31.       }while(adc1>1);
  32.       for(i=0;i<200;i++){
  33.          set_adc_channel(0);
  34.          adc1=read_adc()*3.5/1023.0;
  35.          delay_us(50);
  36.          valorMax1=adc1*adc1+valorMax1;
  37.          set_adc_channel(1);
  38.          adc2=read_adc()*3.5/1023.0;
  39.          delay_us(50);
  40.          valorMax2=adc2*adc2+valorMax2;
  41.       }  
  42.       tension=sqrt(valorMax1/200)*136;
  43.       corriente=sqrt(valorMax2/200)*0.61;
  44.       potencia=tension*corriente;
  45.       lcd_gotoxy(1,1);
  46.       printf(lcd_putc,"     W:%3.1f    ",potencia);
  47.       lcd_gotoxy(1,2);
  48.       printf(lcd_putc,"V:%3.1f  A:%3.3f",tension, corriente);
  49.       if(corriente>2.00){
  50.          lcd_gotoxy(1,2);
  51.          printf(lcd_putc,"Corriente Maxima");    
  52.       }
  53.       valorMax1=0;
  54.       valorMax2=0;
  55.    }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment