Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[PIC] Water flow sensor configuration in counter mode failing

Status
Not open for further replies.

AshleeMakaya

Newbie
Joined
Dec 2, 2017
Messages
4
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
75
may you please help me rectify this problem. i am trying to start a pump and after a certain amount (1liter-4liters) of water, switch off the pump.


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
#include "float2ascii.h"
 
int sgr, wtr, vin, flr, mw, kp, set, conf;
char txt1[7], txt2[7], txt3[7], txt4[7], txt5[7];
 
// Keypad module connections
char  keypadPort at PORTD;
// End Keypad module connections
 
sbit LCD_RS at RC1_bit;
sbit LCD_EN at RC0_bit;
sbit LCD_D4 at RC2_bit;
sbit LCD_D5 at RC3_bit;
sbit LCD_D6 at RC4_bit;
sbit LCD_D7 at RC5_bit;
 
sbit LCD_RS_Direction at TRISC1_bit;
sbit LCD_EN_Direction at TRISC0_bit;
sbit LCD_D4_Direction at TRISC2_bit;
sbit LCD_D5_Direction at TRISC3_bit;
sbit LCD_D6_Direction at TRISC4_bit;
sbit LCD_D7_Direction at TRISC5_bit;
// End LCD module connections
 
char count = 0;
unsigned long counter = 0;
double litersPerSec = 0, litersFlowed, litersPerMinute = 0, litersPerHour = 0, pulsePerSec = 0;
char str[30];
 
void interrupt() {
    if(INTF_bit) {
      counter += 1;
         INTF_bit = 0;
    }
}
 
void main() {
  Keypad_Init();                           // Initialize Keypad
  Lcd_Init();
  delay_ms(100);
    CMCON = 0x07;
    ADCON1 = 0x87;
 
    TRISA = 0xC0;
    TRISB = 0x01;
 
 
    PORTA = 0x00;
    PORTB = 0x00;
                               // Initialize LCD
  Lcd_Cmd(_LCD_CLEAR);                     // Clear display
  Lcd_Cmd(_LCD_CURSOR_OFF);
  Lcd_Out(1, 1, "GLUE PRODUCTION");                 // Write message text on LCD
  Lcd_Out(2, 1, "MACHINE PROJECT");
  delay_ms(100);
  Lcd_Cmd(_LCD_CLEAR);
  Lcd_Out(1, 1, "Ashlee P Makaya");                 // Write message text on LCD
  Lcd_Out(2, 1, "H160305F");
  delay_ms(100);
error1:
  Lcd_Cmd(_LCD_CLEAR);
  Lcd_Out(1, 1, "SELECT CONFIG");                 // Write message text on LCD
  Lcd_Out(2, 1, "1, 2, 3 OR 4");
 
  do {
    kp = 0;                                // Reset key code variable
 
    // Wait for key to be pressed and released
    do
      kp = Keypad_Key_Click();             // Store key code in kp variable
    while (!kp);
   // Prepare value for output, transform key to it's ASCII value
    switch (kp) {
  
 
      case  1: kp = 49; break; // 1        // Uncomment this block for keypad4x4
      case  2: kp = 50; break; // 2
      case  3: kp = 51; break; // 3      case  4: kp = 65; break; // A
      case  5: kp = 52; break; // 4
      case  6: kp = 53; break; // 5
      case  7: kp = 54; break; // 6
      case  9: kp = 55; break; // 7
      case 10: kp = 56; break; // 8
      case 11: kp = 57; break; // 9
      case 13: kp = 42; break; // *
      case 14: kp = 48; break; // 0
      case 15: kp = 35; break; // #
      default: kp += 48;
    }
 
 
  Lcd_Cmd(_LCD_CLEAR);
  Lcd_Out(1, 1, "MACHINE SET TO");
  Lcd_Out(2, 1, "CONFIG : ");
  Lcd_Chr(2, 9, kp);                    // Print Configuration Setting
  delay_ms(100);
 
 
    if (kp == 49 ){
      conf = 1;
      sgr =  300;
      flr =  190;
      vin =   10;
      wtr =    1;
      mw  =   15;
 
      }
    else if (kp == 50 ) {
      conf = 2;                            // ASCII value
      sgr =  600;
      flr =  380;
      vin =   20;
      wtr =    2;
      mw  =   30;
 
      }
    else if (kp == 51 ) {
      conf = 3;
      sgr =  900;
      flr =  570;
      vin =   30;
      wtr =    3;
      mw  =   45;
      }
    else if (kp == 52 ) {
      conf = 4;
      sgr = 1200;
      flr =  760;
      vin =   40;
      wtr =    4;
      mw  =   60;
      }
    else {
      Lcd_Cmd(_LCD_CLEAR);
      Lcd_Out(1, 1, "INVALID SELECTION");
      delay_ms(200);
      goto error1;
      }
  WordToStr(sgr, txt1);                   // Transform counter value to string
  WordToStr(flr, txt2);
  WordToStr(vin, txt3);
  WordToStr(wtr, txt4);
  WordToStr(mw, txt5);
  Lcd_Cmd(_LCD_CLEAR);
  Lcd_Out(1, 1, "SUGAR: ");                 // Write message text on LCD
  Lcd_Out(2, 1, "FLOUR:");
  Lcd_Out(1, 12, txt1);
  Lcd_Out(2, 12, txt2);
  delay_ms(200);
  Lcd_Cmd(_LCD_CLEAR);
  Lcd_Out(1, 1, "VINIGAR: ");                 // Write message text on LCD
  Lcd_Out(2, 1, "WATER:");
  Lcd_Out(1, 12, txt3);
  Lcd_Out(2, 12, txt4);
  delay_ms(200);
  Lcd_Cmd(_LCD_CLEAR);
  Lcd_Out(1, 1, "LIESTERINE: ");
  Lcd_Out(1, 12, txt5);
  delay_ms(200);
 
 
 
    LCD_Cmd(_LCD_CURSOR_OFF);
    LCD_Cmd(_LCD_CLEAR);
    INTEDG_bit = 1;
    INTE_bit = 1;
    PEIE_bit = 1;
    GIE_bit = 1;
 
    INTF_bit = 0;
 
    do{
        portb.f7 = 1;
        pulsePerSec = (double)counter;
        if (conf == 1) {
 
        if(pulsePerSec == 450 ) {
        portb.f7 = 0;
        }
        }
        else if (conf == 2) {
 
        if(pulsePerSec == 900 ) {
        portb.f7 = 0;
        }
        }
        else if (conf == 3) {
 
        if(pulsePerSec == 1350 ) {
        portb.f7 = 0;
        }
        }
        else if (conf == 2) {
 
        if(pulsePerSec == 1800 ) {
        portb.f7 = 0;
        }
        }
 
        litersPerSec = pulsePerSec / 7.5/ 60;
        litersFlowed = litersPerSec;
 
        Float2Ascii(litersFlowed, str, 2);
        strcat(str, " Liters");
        LCD_Out(1,1,str);
 
        Float2Ascii(litersPerSec, str, 2);
        strcat(str, " Ltr/sec");
        LCD_Out(2,1,str);
       }while(1);
 
     } while(1);
    
    }

 

What problem?
You need to tell us what you are expecting, and what is actually happening.
Susan
 
The problem is the flow sensor is not working. The pic is not responding to the pulses.
I want for every pulse, the timer1 H & L to increment thus using it as a counter.
 

Which MCU are you using? (These are really basic pieces of information that we are asking for - you really should look up how to ask a question. For a start, if all you knew was in your first posting in this thread, would you know what it was all about???)
As the 'counter' variable is being updated in an ISR you must declare it volatile, otherwise the compiler does not know that it is being updated elsewhere and is therefore quite within its rights to use a copy.
What timer are you talking about? I can't see where you initialise a timer in your code. Without knowing the MCU, there are a number of ways a timer can be used with an external clock but you don't seem to reference a timer anywhere in your code.
If all you are trying to do is to measure the flow of a liquid, then you seem to have a lot of additional code that does not make sense in this context.
Try stripping the code down to just the part that is causing trouble and get that working before adding back in the rest of the code.
Finally, you have a lot of data being sent to the LCD with a 200mSec delay in between. 200mSec is a very short time and will make the LCD seem to flash and not be readable.
Susan
 

The problem is the flow sensor is not working. The pic is not responding to the pulses.

There is no indication anywhere in your code about the reading of any pin state, so should we assume it is missing some file of your code which you did not send ? Or worse, is it not yet implemented ?

Moreover, at first sight, there are weird constructs in your code, such as the following sequence, ending at lines 210 and 212 without neither break, continue or even (ugh..) goto statement; perhaps the most external loop would be never reached:

Code:
do{
     do{
     }while(1);
} while(1);
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top