PING))) #28015 with PIC18F2550

Thread Starter

Nara Shikamaru

Joined Nov 24, 2007
92
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:

Rich (BB code):
#include <18F2550.h>
#device adc=10
#fuses HSPLL,NOWDT,NOPROTECT,NOLVP,NODEBUG,USBDIV,PLL5,CPUDIV1,VREGEN
#use delay(clock=48000000)

 #define USB_CON_SENSE_PIN PIN_B2

 #include <usb_cdc.h>
 
 
#define LCD_RS PIN_C0 //CONTROL
#define LCD_RW PIN_C1
#define LCD_E PIN_C2

#define LCD_DB4 PIN_A0 //DATOS
#define LCD_DB5 PIN_A1
#define LCD_DB6 PIN_A2
#define LCD_DB7 PIN_A3

#include <flex_lcd.h> //LIBRERIA LCD

float ticks,distancia,nivel_tanque;
void main() {
 //  BYTE i, j, address, value;

   setup_adc_ports(NO_ANALOGS);

   usb_cdc_init();
   usb_init();
   lcd_init();  
   
//      while(!usb_cdc_connected()) {}

   do {

      {
       ticks=0;
            SET_TRIS_b(0x00);
            output_low(PIN_B0);
            output_high(PIN_B0);
            delay_us(5);
            output_low(PIN_B0);
            delay_us(750);
            SET_TRIS_b(0x01);
            while(input(PIN_B0))  //se genera el pulso de disparo
             {                       // del sensor de distancia
               ticks=ticks+1;
               delay_us(10);
             } 
             distancia=ticks*300/18500;
             nivel_tanque=distancia*2643/100;
           //  distancia=distancia*255/3000;  //la distancia queda en milimetros
              delay_ms(100);
      printf(lcd_putc,"\f NIVEL \n #:%f n:%f", distancia,nivel_tanque);
      }

      usb_task();
      
      if (usb_enumerated()) 
      {
      printf(usb_cdc_putc,"\r NIVEL #:%f, nivel:%f", distancia,nivel_tanque);
      }
            
      } while (TRUE);
}
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!!.....
 

Attachments

Top