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.

Problem in IF loop using PIC16F630

Status
Not open for further replies.

srevish

Member level 2
Member level 2
Joined
Apr 23, 2013
Messages
48
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Visit site
Activity points
1,661

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
if(time<=2)
function();
else if(time>2 && time<30)
 function1();
else if(time==30)     //----------------------- problem in this time 
 {
function1();
 if(dew_input) {dew_flag=0;}
else {dew_flag=1;}
}
 else if(time>=31 && time<=120)
function2();
 else if(time>121 && time<150)
function3();
else if(time==150)
{
function3();
if(dew_input) {dew_flag=0;}
else {dew_flag=1;}
}
else if(time>151 && time<=240 )
function4();




For the above IF loop i am having problem when the time is equal to 30.

The program is working well for sometimes, even more then a weak but suddenly it is getting problem.

The problem is when time is equal to 30, the program misses its operation and jumps to next step. When I restarts the system then it again starts to work function normally, but after some time I am getting this problem.

Can any one tell me how to solve this problem and why these types of problem occurs.

thanks
 

I can't see anything wrong wih the code although it might be possible to restructure it to be more efficient. Possibly the large number of 'if' instructions has made the compiler produce poor code or something else clashes (some interrupt code or timer perhaps) at the same instant the value is 30.

You could try this method instead, it usually produces less code:
1. if 'time' is updating constantly, take and use a copy of it so the value doesn't change while running this part of the code.
2. instead of checking for the upper and lower values each time, check the difference between them and subtract the lower value from the result each time.

So 'time' (or the copy you made of it) reduces as it goes through each check and you only have to test for equality or the maximum difference.

Brian.
 
Dear Brain,

Thank you very much for your reply.

I could not able to understand the steps you suggested me to reduce the codes. Can you please explain it with the codes ( atleast for few lines), this is very much helpful for me.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top