glamo
June 25, 2022, 1:38pm
1
I'm trying to make a comparator, if the input voltage changes slowly, everything works normally, however, If I quickly turn the potentiometer (I wired to the input), the two outputs are actives at the same time !
(I don't want to slow down the input response.)
My code is:
double gap = abs((SetLevel - Hyst) - analog_input_1);
double gap2 = abs((SetLevel + Hyst) - analog_input_1);
if (analog_input_1 >= (SetLevel - Hyst))
if (analog_input_1 >= (SetLevel + Hyst))
{
downout = gap2 ;
upout == 0;
}
else
{
downout == 0;
}
analogWrite(DWN,downout);
if (analog_input_1 <= (SetLevel - Hyst))
if (analog_input_1 <= (SetLevel + Hyst))
{
upout = gap;
downout == 0;
}
else
{
upout == 0;
}
analogWrite(UP,upout);
J-M-L
June 25, 2022, 1:40pm
2
glamo:
My code is:
that's not your code it's a (poorly indented) snippet (Snippets R Us! )
if Hyst is positive and not null then if analog_input_1 is less or equal to (SetLevel - Hyst) then you are sure it's less than (SetLevel + Hyst)...
something fishy there
Hi, @glamo
It would be better for you to post your complete code.
If it is very big and involved, then write some code that JUST uses the inputs, variables and outputs involved.
If you wrote this code in stages, you should already have such a section of code.
Thanks.. Tom...
glamo
June 25, 2022, 1:58pm
5
Hello JML,
Of course this code is not created by my self, it is from Arduino Gods
glamo
June 25, 2022, 2:05pm
7
Thanks Tom Gerge, you are so kind as usual.
When there is a slow voltage change, everything works correctly, but when the fast voltage changes, it is not worked, I try to understand the reason
Hi,
A circuit diagram would also help.
What model Arduino controller are you using?
I would think ONE if... else... statement with some conditional logic in it would work.
Pseudo code.
Read INPUT
if( (INPUT >= (Setlevel - Hyst) && INPUT <= (Setlevel + Hyst))
{
INPUT INSIDE WINDOW
}
else
{
INPUT OUTSIDE WINDOW
}
Something like that.
Tom...
Hello glamo
Take a view here to design a window comparator:
The Arduino programming language Reference, organized into Functions, Variable and Constant, and Structure keywords.
Have a nice day and enjoy programming in C++ and learning.
Errors and omissions excepted.
Дайте миру шанс!
glamo
June 25, 2022, 2:37pm
11
Thanks Tom, I am using Arduino Uno.
I will try your code
glamo
June 25, 2022, 2:44pm
13
I hope someone with eagle eyes will see the problem line
J-M-L
June 25, 2022, 3:27pm
14
it's possibly in the code you did not post...
➜ do yourself a favour and please read How to get the best out of this forum and post accordingly
No, my crystalball is in the dish washer
Paul_B
June 26, 2022, 7:08am
17
er_name_not_found:
Top rack only
Not sure. How heat resistant is fairy dust?
I know that if you don't keep them covered, they can burn your house down, but the lens doesn't have to get too hot to focus the energy.
glamo
June 26, 2022, 1:44pm
19
Hello Tom,
The problem mentioned only occurs in fast voltage changes
Is there any way to calculate or measure the code instruction time/cycle?
Hi,
Did you write some code using my pseudo code as a guide?
It would have been fewer lines than your original code.
How are you monitoring the changes?
If you are using the Serial monitor on the IDE, make sure you use 115200 baud rate.
Your COMPLETE code would help us work out your problem.
To add code please click this link;
See also FAQ - Arduino Forum for general rules on forum behaviour and etiquette.
Hello,
Welcome to the Arduino Forum.
This guide explains how to get the best out of this forum. Please read and follow the instructions below.
Being new here you might think this is having rules for the sake of rules, but that is not the case. If you don’t follow the guidelines all that happens is there is a long exchange of posts while we try to get you to tell us what we need in order to help you, which is fru…
Are you trying to control a PWM output, if so where are your lines of code to prevent the PWM value not going below 0 or higher than 255?
Why use a pot and not a centre off SPDT instead of a pot?
Thanks.. Tom...
Hi,
Can you explain the logic behind using a pot, window comparator and a PWM output are supposed to work?
If the pot value is inside the window, what is supposed to happen/output?
If the pot value is outside the window, what is supposed to happen/output?
OR ARE YOU TRYING;
If the pot value is above the window, what is supposed to happen/output?
If the pot value is inside the window, what is supposed to happen/output?
If the pot value is below the window, what is supposed to happen/output?
Tom....