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.

In range function check arduino

Status
Not open for further replies.

nayakajit87

Member level 5
Joined
Aug 13, 2018
Messages
84
Helped
0
Reputation
0
Reaction score
0
Trophy points
6
Activity points
1,065
Here is my code written on Arduino.I wanted to load OL_Time value if
R,Y, current range of

Code:
if(perc1>RYBcurrent OL_Time=20
else
if(perc5>RYBcurrent OL_Time=15
else
if(perc15>RYBcurrent OL_Time=10
else
if(perc20>RYBcurrent)
OL_Time=5



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
unsigned int OL_Point = 10;
unsigned int percentage2C_Limit = 20;
unsigned int percentage5C_Limit = 50;
unsigned int percentage10C_Limit = 100;
unsigned char OL_Curve = 1;
unsigned int OverLoad_Flag = 0;
unsigned char Pgm_mode = 0;
unsigned int OCRT_Dly_Cntr = 0;
unsigned int OL_Time = 30;
unsigned int OLTR_Time = 0;
unsigned char Milli10_Sec_Cntr_X = 0, Milli100_Sec_Cntr_X = 0, Milli1000_Sec_Cntr_X = 0, Power_on_Valid_Cntr = 0;
unsigned char Cntrl_flag = 1;
unsigned int Rph_Current = 16;
unsigned int Yph_Current = 16;
unsigned int Bph_Current = 16;
unsigned int Percenatge_Calculated = 0;
unsigned int Counter_OCRT = 0;
unsigned char Rph_OLFlag = 0;
unsigned char Bph_OLFlag = 0;
unsigned char Yph_OLFlag = 0;
float Rph_Current_Float = 0.0;
float Yph_Current_Float = 0.0;
float Bph_Current_Float = 0.0;
 
float OL_Point_Float = 0.0;
 
float Per1_Cal = 0, Per5_Cal = 0, Per10_Cal = 0, Per15_Cal = 0, Per20_Cal = 0;
float Per30_Cal = 0, Per40_Cal = 0, Per50_Cal = 0, Per60_Cal = 0, Per70_Cal = 0, Per80_Cal = 0, Per90_Cal = 0, Per100_Cal = 0;
 
void setup() {
  // put your setup code here, to run once:
 
  Serial.begin(9600);
 
}
 
void loop()
 
{
 
  if (((Rph_Current > OL_Point) || (Yph_Current > OL_Point) || (Bph_Current > OL_Point))) {
    if (OL_Curve == 1) {
      Percenatge_Calculated = ((int)(OL_Point * percentage2C_Limit) + OL_Point);
      Rph_Current_Float = Rph_Current * 1.0;
      Yph_Current_Float = Yph_Current * 1.0;
      Bph_Current_Float
 
        = Bph_Current * 1.0;
      OL_Point_Float = (double) OL_Point / 1.0;
 
      Per1_Cal = (OL_Point_Float + ((OL_Point_Float * 1) / 100));
      Per5_Cal = (OL_Point_Float + ((OL_Point_Float * 5) / 100));
      Per10_Cal = (OL_Point_Float + ((OL_Point_Float * 10) / 100));
      Per15_Cal = (OL_Point_Float + ((OL_Point_Float * 15) / 100));
      Per20_Cal = (OL_Point_Float + ((OL_Point_Float * 20) / 100));
 
      // Percenatge_Calculated= OL_Point+((OL_Point*1)/100;
 
      Counter_OCRT++;
 
 
      function ();
 
    }
 
  } else {
 
    // Counter_OCRT = 0;
    OverLoad_Flag = 0;
    Rph_OLFlag = 0;
    Bph_OLFlag = 0;
    Yph_OLFlag = 0;
  }
  delay(1000);
 
  Serial.print("RPH:");
  Serial.print(Rph_Current);
  Serial.print("\tYPH:");
  Serial.print(Yph_Current);
  Serial.print("\tBPH:");
  Serial.print(Bph_Current);
  Serial.print("\t OL_Point_Float:");
  Serial.println(OL_Point_Float);
  Serial.print("RPH-float:");
  Serial.print(Rph_Current_Float);
  Serial.print("\tYPH-float:");
  Serial.print(Yph_Current_Float);
  Serial.print("\tBPH-float:");
  Serial.println(Bph_Current_Float);
  Serial.print("Per1_Cal:");
  Serial.print(Per1_Cal);
  Serial.print("\tPer5_Cal:");
  Serial.print(Per5_Cal);
  Serial.print("\tPer10_Cal :");
  Serial.print(Per10_Cal);
  Serial.print("\tPer15_Cal:");
  Serial.print(Per15_Cal);
  Serial.print("\tPer20_Cal:");
  Serial.println(Per20_Cal);
  Serial.print("OL_Time:");
  Serial.println(OL_Time);
  Serial.println("...................................................................................");
  delay(1000);
}
 
void
function () {
 
  if (Counter_OCRT >= 5) {
    // OverLoad_Flag = 1;
    Counter_OCRT = 0;
 
    if ((Rph_Current_Float >= Per1_Cal) && (Per5_Cal <= Rph_Current_Float) || (Yph_Current_Float >= Per1_Cal) && (Per5_Cal <= Yph_Current_Float) || (Bph_Current_Float >= Per1_Cal) && (Per5_Cal <= Bph_Current_Float)) {
      OL_Time = 20;
      OverLoad_Flag = 1;
    } else if ((Rph_Current_Float >= Per5_Cal) && (Per10_Cal <= Rph_Current_Float) || (Yph_Current_Float >= Per5_Cal) && (Per10_Cal <= Yph_Current_Float) || (Bph_Current_Float >= Per5_Cal) && (Per10_Cal <= Bph_Current_Float)) {
      OL_Time = 15;
      OverLoad_Flag = 1;
    } else
 
      if ((Rph_Current_Float >= Per10_Cal) && (Per15_Cal <= Rph_Current_Float) || (Yph_Current_Float >= Per10_Cal) && (Per15_Cal <= Yph_Current_Float) || (Bph_Current_Float >= Per10_Cal) && (Per15_Cal <= Bph_Current_Float)) {
        OL_Time = 10;
        OverLoad_Flag = 1;
      } else if ((Rph_Current_Float >= Per20_Cal) || (Yph_Current_Float >= Per20_Cal) && (Bph_Current_Float >= Per20_Cal)) {
        OL_Time = 5;
        OverLoad_Flag = 1;
      }
 
  }
 
}

 

What is stopping you from doing this? Except for the lack of brackets closing the numerical evaluations as well as missing semicolons in the snippet above which would issue a compilation error, otherwise there is not reason for it does not work.
 

its working code i posted here. its compiling arduino and printing proper data. but i am fail to meet this condition

if(perc1>RYBcurrent OL_Time=20
else
if(perc5>RYBcurrent OL_Time=15
else
if(perc15>RYBcurrent OL_Time=10
else
if(perc20>RYBcurrent)
OL_Time=5
 

its working code i posted here. its compiling arduino and printing proper data. but i am fail to meet this condition

In the program you posted there are other conditions being evaluated along with those posted in the above snippet, so you should test one feature at a time, ie commenting the other conditions. Anyway, since you are in the Arduino environment, why not use the serial port terminal feature to debug the program? Simply saying that "you're failing to meet this condition" gives the impression that you did not much more investigations on the system itself; even a LED could be used to tell you which parts of the code are being reached or not.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top