![]() ![]() xTaskCreatePinnedToCore( fCollectHistory, "fCollectHistory", 10000, NULL, 4, NULL, 1 ) Then define the tasks that will be running once a second. XEventGroupSetBitsFromISR( eg, evtGroupBits, &xHigherPriorityTaskWoken ) I'd then set up a hardware timer callback. I create a hardware timer, and set the timer to trigger once a second. TimerAlarmWrite(timer, 1000, true) // trigger once a ms. ![]() TimerAttachInterrupt( timer, &onTimer, true ) In setup() timer = timerBegin( 3, 80, true ) #define evtGroupBits ( evtCollectHistory | evtDoDisplay ) I'd set up a hardware timer and use an event group to get a precision 1 second interrupt. I guess later in the future if you came across such a situation of wanting a part of your code executing once every second and another part execute once every 0, 01 seconds the question how to do that will arise.Īnd then it is time to UN-learn delay and to learn how non-blocking timing based on millis() works. execute a command once every 0,1 secondsīecause with delay you command your microcontroller to take 100% of his calculation-ressources to " wait" until the delay-time is over.īut you seem to be set on railroads to let the train run on the delay-track.for incoming data and react as soon as possible as the data rushes in.for a button-press and react immitiately on the button-press. ![]() The microcontroller can do absolutely nothing else. This version will auto-correct to make the loop execute once per second even if you add more commands.īut because you command your microcontroller to take 100% of his calculation-ressources to " wait" until the delay-time is over I need to use the unsigned long data type going to try something like: I do see I made a mistake in my previous code snippet as pointed out. A means for detecting when a time slice has been run over is nice. They will all do something when (if) that happens, so either don't let that happen or know that what will is OK. * make loop use a defined amount of time */Īll the methods on this thread will have one kind or another problem with any processing that overflows the time allowed. I can assure you that this same method can bear a bit of extrapolation and be exploited in some more complicated timing scenarios. It is refreshing to see something that someone actually thought out and coded. If you don't post all this information because you want a "quick answer" to your detail problem It is very likely to turn out that all that happens is having mutliple waiting-times with mutliple asking back for details until the other users do have a clear picture of what you want to do.īest regards I was charmed by your approach in #10 and am compelled to call attention to it, here I post it with a simple job of printing millis() and no surprise it works perfectly and would be indistinguishable from the outside compared to other more like idiomatic approaches. Did you post the complete compiler-output into a code-section? ![]() if relevant did you post a handdrawn schematic or your wiring?.if relevant did you post a link to a datasheet of each component you are using?.do you have a digital multimeter (DMM) Yes / No).description of the functionality you want to have written in normal works avoiding programming terms.description of your knowledge about electronics.description of your programming skills and knowledge.did you write which exact type of microcontroller you are using?.So please go through this checklist and if you find an item you haven't posted yet post it To speed up finishing your project you should invest some time into writing additional information I'm 100% sure that this WILL speed up finishing your project. You are welcome on this forum! You are working on an informatic project and what is most needed in an informatic project is information imagine: do the other users here in the forum have a clear picture of what you are trying to do? Your freeze(waitTime ) oh sorry your delay(waitTime ) again does freeze your microcontroller. Recently a user wrote "delay() is the wrong name for this function So a line of code that would - at least compile would be unsigned long waitTime = 1000 - timeelapsed It should be float waitTime = 1000 - timeelapsed ĪLL variables that are used with millis() must be of type unsigned long Has an error: you haven't named a variable Your proposed solution shows that you have not yet understood how non-blocking timing works.įirst of all a codeline like float = 1000 - timeelapsed ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |