PING))) #28015 with PIC18F2550

Discussion in 'Embedded Systems and Microcontrollers' started by Nara Shikamaru, Mar 10, 2010.

  1. Nara Shikamaru

    Thread Starter Active Member

    Nov 24, 2007
    92
    3
    Hey Everybody!

    Im doing a circuit that must measure constantly the Level inside a Tank, i.ve done the circuit and it works! but after a couple of minutes the Sensor and PIC stops working and just turning it off and on again makes it work for another couple more minutes....i dont know if its the code or what, but how can i fix it!!....

    the circuit flow sequence is as follows:

    1) System iniciated

    2) Start the PING))) #28015

    3) If the level in Tank is = to low level, Turn on the Pump

    4) If the level in Tank is < than Low Level, Turn on the pump, turn on the Alarm

    5) If the Level in tank is = to High Level, Turn off the Pump

    6) If the level in tank is > of high level, turn off the pump, turn on the Alarm

    That must be Cyclic!, and constantly show the Level in an LCD....


    Here i`ll put you the code:

    Code ( (Unknown Language)):
    1.  
    2. #include <18F2550.h>
    3. #device adc=10
    4. #fuses HSPLL,NOWDT,NOPROTECT,NOLVP,NODEBUG,USBDIV,PLL5,CPUDIV1,VREGEN
    5. #use delay(clock=48000000)
    6.  
    7.  #define USB_CON_SENSE_PIN PIN_B2
    8.  
    9.  #include <usb_cdc.h>
    10.  
    11.  
    12. #define LCD_RS PIN_C0 //CONTROL
    13. #define LCD_RW PIN_C1
    14. #define LCD_E PIN_C2
    15.  
    16. #define LCD_DB4 PIN_A0 //DATOS
    17. #define LCD_DB5 PIN_A1
    18. #define LCD_DB6 PIN_A2
    19. #define LCD_DB7 PIN_A3
    20.  
    21. #include <flex_lcd.h> //LIBRERIA LCD
    22.  
    23. float ticks,distancia,nivel_tanque;
    24. void main() {
    25.  //  BYTE i, j, address, value;
    26.  
    27.    setup_adc_ports(NO_ANALOGS);
    28.  
    29.    usb_cdc_init();
    30.    usb_init();
    31.    lcd_init();  
    32.    
    33. //      while(!usb_cdc_connected()) {}
    34.  
    35.    do {
    36.  
    37.       {
    38.        ticks=0;
    39.             SET_TRIS_b(0x00);
    40.             output_low(PIN_B0);
    41.             output_high(PIN_B0);
    42.             delay_us(5);
    43.             output_low(PIN_B0);
    44.             delay_us(750);
    45.             SET_TRIS_b(0x01);
    46.             while(input(PIN_B0))  //se genera el pulso de disparo
    47.              {                       // del sensor de distancia
    48.                ticks=ticks+1;
    49.                delay_us(10);
    50.              }
    51.              distancia=ticks*300/18500;
    52.              nivel_tanque=distancia*2643/100;
    53.            //  distancia=distancia*255/3000;  //la distancia queda en milimetros
    54.               delay_ms(100);
    55.       printf(lcd_putc,"\f NIVEL \n #:%f n:%f", distancia,nivel_tanque);
    56.       }
    57.  
    58.       usb_task();
    59.      
    60.       if (usb_enumerated())
    61.       {
    62.       printf(usb_cdc_putc,"\r NIVEL #:%f, nivel:%f", distancia,nivel_tanque);
    63.       }
    64.            
    65.       } while (TRUE);
    66. }
    67.  
    im using CCS Compiler and PROTEUS for simulation, ill upload the schematic in the ISIS PROTEUS file and a image if you use another simulator, the ultrasonic sensor im simulating it with a Function gen!!

    I Hope you can help me!....Remember!.....i dont understand why it "hangs up" i call the people at parallax and they told me the Circuit can work continuosly!!.....
     
Loading...