Hi friends,
I want to get timer interrupt's execution time from serially available data in the following program. I tried but unable to solve it.
Please help me.
Do I understand your question is really "how can I enter and recognize a value typed on the serial monitor, so that I can use it in my code to do something?"
parikshitsaha:
Timer1.initialize(20000000); // in microseconds (1000000*t second)
I am interested to give this the value inside "Timer1.initialize" from serial monitor.
if am going to put it inside "void loop" Timer interrupt is not executing.
And if am going to do serial.read from "void setup" then it'll not run real-time always without doing hardware reset.
Please help me solve this out.
J-M-L:
Do I get it right you want to do something every 2 seconds ?
yes but 2sec is not always fixed. i'm going to give it realtime while executing and from serial monitor it'll get it whether its 2sec or 5sec or something else.
J-M-L:
Do you want to read the serial just once in setup or do you want to be able to change the period also whilst the loop is looping?
I want to be able to change the period also whilst the loop is looping.
J-M-L:
You don’t need a timer nor an interrupt for that... just use millis()
parikshitsaha:
My code has also hardware interrupt along with the timer interrupt. millis(), as well as hardware interrupt both are not working same time.
There is no problem with millis() and correctly programmed interrupts.
Serial use interrupts too... and if your typical timing is 2s or 5s then not sure there is a need for interrupts (unless the loop takes a reeaaaaaaalllly long time to execute)
Use the serial tutorial pointed above to add getting a message from the console and use atol() to convert that to a number when you got an entry
My plan, as well as the code, is for running a motor for a specific duration of time (time is taken from serial monitor). and in the meanwhile if I pressed the interrupt switch it'll be going to be stopped else it'll run for the serially read time duration & get stopped.