CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Liquid dispenser

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
ferrousduke



Joined: 31 Mar 2008
Posts: 29
Location: Mumbai, India

View user's profile Send private message Visit poster's website

Liquid dispenser
PostPosted: Sun Aug 23, 2009 7:29 am     Reply with quote

Hello,
I am working on a liquid dispenser that would dispense some amount of liquid (alcohol based) once it detects an object (like hand) placed underneath it. Logic of operation is quite simple. I am including a flow chart with it. Please help me fill gaps in my code. Problem comes with #int_ext. I am making an infinite loop with the code below.

Code:
#if defined(__PCH__)
#include <16F84A.h>
#include <input.c>
#include <math.h>
#use delay(clock = 4000000)
#endif
#define IR_detect PIN_B0;

#int_ext
{
   //{
     //here I want to set the flag, PIC wakes up and does an interrupt routine.
   //}
   check_again(); // it will check whether even after 500 mS the object is present or not
   
}

void actuate_solenoid (void);
void check_again(void);

void check_again()
{
   int i;
   for(i = 0; i < 100; i++)
   {
      delay_ms(5);
   }
   
   //{
     //here I want to clear the flag so to further wait for the interrupt.
   //}
 
   enable_interrupts(INT_EXT); // Is this the way to again enable the same interrupt?
   enable_interrupts(GLOBAL);  // According to me, it will be in a loop till the hand is removed
   ext_int_edge(L_TO_H);       //

   if(flag)
   {
      actuate_solenoid();
   }
   else
   { 
      break;
   }
   
}

void actuate_solenoid()
{
   for(int i, i < time; i++)
   {
      OUTPUT_HIGH(PIN_B1); //solenoid activates
      delay_ms(1);
   }
   OUTPUT_LOW(PIN_B1); //solenoid deactivates blocking liquid supply.
   
   //here I should let PIC in sleep mode. and wait for the next interrupt to happen. Return to main.
   
}


void main()
{

   //setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
   enable_interrupts(INT_EXT); // IF hand is placed, it will be notified by L_TO_H
   enable_interrupts(GLOBAL);
   ext_int_edge(L_TO_H);
   
   // PIC sleep mode activated
   
}

bela



Joined: 31 Aug 2008
Posts: 27
Location: Bedford, BEDS UK

View user's profile Send private message Visit poster's website

PostPosted: Sun Aug 23, 2009 8:54 am     Reply with quote

You should not have the ISR taking so long. Also, there's no need to actually 'do anything' for a wake up interrupt.

Code:


#INT_EXT
void ext_isr()
{
   return;
}

boolean check_again()
{
   delay_ms(500);
   if(!input(IR_detect))return(true);
   else return(false);
}

main()
{
   ext_int_edge(L_TO_H);
   enable_interrupts(GLOBAL);

   while(TRUE) {
      enable_interrupts(INT_EXT);
      sleep();
      disable_interrupts(INT_EXT);
      /* now we have been woken by the interrupt */

      if(!check_again())continue;
     
      actuate_solenoid();
      while(!input(IR_detect));    //wait for the hand to be removed

   }

}
ferrousduke



Joined: 31 Mar 2008
Posts: 29
Location: Mumbai, India

View user's profile Send private message Visit poster's website

PostPosted: Sun Aug 23, 2009 2:54 pm     Reply with quote

Hi Bela,
I have attached a code file with proteus file. I am not getting an output at PIN_B2. I have added a pushbutton as an alternative to IR sensor.

http://www.filefactory.com/file/ah3d93c/n/code_rar

http://www.mediafire.com/?sharekey=6b52546c5529723ad2db6fb9a8902bda
ferrousduke



Joined: 31 Mar 2008
Posts: 29
Location: Mumbai, India

View user's profile Send private message Visit poster's website

PostPosted: Mon Aug 24, 2009 1:26 am     Reply with quote

Can anyone please help with the code?
bela



Joined: 31 Aug 2008
Posts: 27
Location: Bedford, BEDS UK

View user's profile Send private message Visit poster's website

PostPosted: Mon Aug 24, 2009 2:25 am     Reply with quote

Hi,

First thing: int8 i cannot count up to 1000; 255 max. Normally, replace int8 with long but this time, I'd be tempted to just do this:

Code:

void activate_solenoid()
{
   output_high(PIN_B2);
   delay_ms(1000);
   output_low(PIN_B2);
}


also, your i does not have an initializer; you can't guarantee that it will be zero so; for(i=0;i<1000;i++)

Let me know what happens.

Darren.
ferrousduke



Joined: 31 Mar 2008
Posts: 29
Location: Mumbai, India

View user's profile Send private message Visit poster's website

PostPosted: Mon Aug 24, 2009 5:47 am     Reply with quote

Hey,
THanks for your reply. I fixed the code but ext_int_edge(L_TO_H) does not work.. I had to change it to H_TO_L. Quite strange.
ferrousduke



Joined: 31 Mar 2008
Posts: 29
Location: Mumbai, India

View user's profile Send private message Visit poster's website

what am I doing wrong?
PostPosted: Tue Aug 25, 2009 5:38 am     Reply with quote

operation faulty_indication() should ring only when power is not connected to relay. for me it shows even if the power is ok.. it blinks twice if the power is not available to relay and blinks once after the operation is finished even when everything is alright.

Below is the code:
Code:
#INT_EXT
void ext_isr()
{
   return;
}

boolean verify()
{
   delay_ms(time);
   if(!input(IR_detect) && input(PIN_B1))  //Making sure Hand is still present
   {                                       //and Power is connected to relay.
      return(true);
   }
   else
   {
      fault_indication();
      return(false);
   }
}

void fault_indication()
{
   int8 i;
   for(i = 0; i < 5; i++)
   {
      output_high(PIN_B4); //Glows LED showing malfunction in relay.
      delay_ms(200);
      output_low(PIN_B4);
      delay_ms(200);
   }
}

void activate_solenoid()
{                 
      output_high(PIN_B2);             //solenoid activates
      delay_ms(activated_time);
      output_low(PIN_B2);              //solenoid deactivates blocking liquid supply.
}

void main()
{
   ext_int_edge(H_TO_L);
   enable_interrupts(GLOBAL);

   while(TRUE)
   {
      enable_interrupts(INT_EXT);
      sleep();
      disable_interrupts(INT_EXT);

      if(!verify())continue;
     
      activate_solenoid();          //Solenoid is activated and deactivated.
      while(!input(IR_detect));     //waiting for the hand to be removed.
   }
}
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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