+ Post New Thread
Results 1 to 10 of 10
-
30th April 2019, 10:36 #1
- Join Date
- May 2010
- Location
- usa
- Posts
- 313
- Helped
- 0 / 0
- Points
- 2,933
- Level
- 12
how to set and reset pin in microcontroller
I enabled timer and i want to set and reset pin in microcontroller every two hours, how to do that? i mean i want the pin on for 2 hours and off for another 2 hours.
Last edited by mshh; 30th April 2019 at 10:52.
-
Advertisement
-
30th April 2019, 11:21 #2
Awards:
- Join Date
- Apr 2014
- Posts
- 16,046
- Helped
- 3634 / 3634
- Points
- 79,050
- Level
- 68
Re: how to set and reset pin in microcontroller
Hi,
what a question...
Neither clear whether the timing is the problem or set/clear a pin
nor does it give a clue about microcontroler, language or compiler.
so: How can we help?
Hint: it is a very basic task (or two tasks) which has been discussed numerous times in the internet and the forum...
What have you done so far to find a solution on your own.
KlausPlease don´t contact me via PM, because there is no time to respond to them. No friend requests. Thank you.
-
30th April 2019, 11:47 #3
- Join Date
- May 2010
- Location
- usa
- Posts
- 313
- Helped
- 0 / 0
- Points
- 2,933
- Level
- 12
Re: how to set and reset pin in microcontroller
the problem is i want to set and reset it every 2 hours and every state hold its value for 2 hours
for example
Code:if( hour=1&minute=59)/// this will set it every 2 hours but it will reset after 1 minute when the condition is false. { set }
Last edited by mshh; 30th April 2019 at 12:11.
-
Advertisement
-
30th April 2019, 12:32 #4
Awards:
- Join Date
- Apr 2014
- Posts
- 16,046
- Helped
- 3634 / 3634
- Points
- 79,050
- Level
- 68
Re: how to set and reset pin in microcontroller
Hi,
Still unclear what the problem is.
if( hour=1&minute=59)/// this will set it every 2 hours but it will reset after 1 minute when the condition is false.
{
set
}
What about a simple flow chart? You think it´s useless? Or a timing diagram...
What about using a simulator or emulator?
KlausPlease don´t contact me via PM, because there is no time to respond to them. No friend requests. Thank you.
-
Advertisement
-
30th April 2019, 12:38 #5
- Join Date
- May 2010
- Location
- usa
- Posts
- 313
- Helped
- 0 / 0
- Points
- 2,933
- Level
- 12
Re: how to set and reset pin in microcontroller
Code:if( hour=1&minute=59)/// this will set it every 2 hours but it will reset after 1 minute when the condition is false. { set } else // when (hours=0&minute=0 or hours=1&minute= 0 or hours=0&minute=59) { reset /// for two hours but time is changing so will the condition }
Last edited by mshh; 30th April 2019 at 12:50.
-
30th April 2019, 12:48 #6
Awards:
- Join Date
- Apr 2014
- Posts
- 16,046
- Helped
- 3634 / 3634
- Points
- 79,050
- Level
- 68
Re: how to set and reset pin in microcontroller
Hi,
I think it´s time for a little effort on your own. At least for giving complete informations and specifications. And give some clarifications according post#2.
For example:
We don´t know where "hour" and "minute" come from. We don´t know whether this is absolute time in 12h or 24h format or if you may reset the variables as you like.
KlausPlease don´t contact me via PM, because there is no time to respond to them. No friend requests. Thank you.
-
2nd May 2019, 20:38 #7
- Join Date
- Dec 2009
- Location
- USA
- Posts
- 54
- Helped
- 15 / 15
- Points
- 2,107
- Level
- 10
Re: how to set and reset pin in microcontroller
Is this for the Arduino?
If yes, then just use the millis() fucntion.
If not then which which micro-controller?
Typically, a Hardware Timer will trigger an interrupt.
Every Timer Interrupt increments a variable until the desired Count ( 2 Hours ) is reached.
Then simply Toggle the Output Bit, reset the variable and repeat forever.
-
2nd May 2019, 22:19 #8
Awards:
- Join Date
- Jul 2009
- Location
- Aberdyfi, West Wales, UK
- Posts
- 13,446
- Helped
- 4487 / 4487
- Points
- 82,003
- Level
- 69
Re: how to set and reset pin in microcontroller
How about:
if (hour % 4) set;
else reset;
or even simpler:
output = (hour & 0x02);
Brian.PLEASE - no friends requests or private emails, I simply don't have time to reply to them all.
It's better to share your questions and answers on Edaboard so we can all benefit from each others experiences.
-
Advertisement
-
3rd May 2019, 13:29 #9
- Join Date
- Dec 2009
- Location
- USA
- Posts
- 54
- Helped
- 15 / 15
- Points
- 2,107
- Level
- 10
-
14th July 2019, 21:47 #10
- Join Date
- Dec 2012
- Location
- New Delhi
- Posts
- 1,209
- Helped
- 182 / 182
- Points
- 6,247
- Level
- 18
Re: how to set and reset pin in microcontroller
Ok. Let's assume your timer generates interrupt every 100mS.
Now declare a variable as Int or Word (I.e. 16 bits) named Counter.
Declare another variable as 2-hour-flag.
In your 100mS isr, increment the Counter. Also if Counter is >= 72000, then SET 2-hour-flag.
Now in your main routine, setup a loop which checks 2-hour-flag. When it is SET, then TOGGLE your outputpin, and also set 2-hour-flag and Counter to zero.
That's your full code right there.
Of course if your timer interruots at a different rate, then calculate the '72000' accordingly.
- - - Updated - - -
Okay, slight error in above. The variable for Counter naturally has to be defined to be able to hold the count required. So select accordingly. Typical Int will not hold 72000, only upto 65535.
+ Post New Thread
Please login