Hi, all!
I have: 2 periodic task with time 10 and 3 ms. Code: 1) config.c : unsigned long long common_ticktime__ = 1000000ULL; /*ns*/ unsigned long greatest_tick_count__ = (unsigned long)18446744073709551601UL; /*tick*/ // greatest_tick_count__ = (unsigned long)0xFFFFFFFFFFFFFFF1 // for main target unsigned long = 32 bit -> greatest_tick_count__ = 0xFFFF FFF1 = 4294967281 (dec) 2) plc_main.c: unsigned long __tick = 0; void __run(void) { __tick++; if (greatest_tick_count__) __tick %= greatest_tick_count__; ... config_run__(__tick); ... } 3) resource1.c: void RESOURCE1_run__(unsigned long tick) { TASK1 = !(tick % 10); TASK2 = !(tick % 3); if (TASK1) { PROGRAM_DO1_body__(&INSTANCE1); } if (TASK2) { PROGRAM_DO2_body__(&INSTANCE2); } } What do We see when __tick = greatest_tick_count__? First. __tick = 0 Second. Call TASK1 and TASK2. Third. Invalid period calls TASK1 Time diagram: __tick = 4294967270. Call TASK1 (period = 10 ms) __tick = 4294967271. Call TASK2 (period = 3 ms) __tick = 4294967274. Call TASK2 (period = 3 ms) __tick = 4294967277. Call TASK2 (period = 3 ms) __tick = 4294967280. Call TASK1 (period = 10 ms) Call TASK2 (period = 3 ms) Moment: __tick = greatest_tick_count__ = 4294967281 -> __tick == 0 __tick = 0. Call TASK1 (period = 10 ms) Error! Delta TASK1 (10 ms) = 1. Call TASK2 (period = 3 ms) Error! Delta TASK2 (3 ms) = 1 __tick = 3. Call TASK2 (period = 3 ms) __tick = 6. Call TASK2 (period = 3 ms) __tick = 9. Call TASK2 (period = 3 ms) __tick = 10. Call TASK1 (period = 10 ms) It's a bag? Regards, Aleksandr Safronov! ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot _______________________________________________ Beremiz-devel mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/beremiz-devel |
Hi Aleksandr Yes, the implementation of periodic tasks is not strictly correct when the timer overflows. To be honest I have always considered that the currently taken approach to implement periodic tasks is not ideal. It needs to be completely revamped/changed. I know how I would like to do it, but once again it implies changes to all the systems that provide runtime support for matiec compiled programs, so I have never bothered fixing this. Cheers, Mario. On Monday, April 09, 2018 15:12:41 [hidden email] wrote: > Hi, all! > > I have: 2 periodic task with time 10 and 3 ms. > Code: > > 1) config.c : > unsigned long long common_ticktime__ = 1000000ULL; /*ns*/ > unsigned long greatest_tick_count__ = (unsigned > long)18446744073709551601UL; /*tick*/ > // greatest_tick_count__ = (unsigned long)0xFFFFFFFFFFFFFFF1 > // for main target unsigned long = 32 bit -> greatest_tick_count__ = > 0xFFFF FFF1 = 4294967281 (dec) > > 2) plc_main.c: > unsigned long __tick = 0; > void __run(void) > { > __tick++; > if (greatest_tick_count__) > __tick %= greatest_tick_count__; > ... > config_run__(__tick); > ... > } > > 3) resource1.c: > void RESOURCE1_run__(unsigned long tick) { > TASK1 = !(tick % 10); > TASK2 = !(tick % 3); > if (TASK1) { > PROGRAM_DO1_body__(&INSTANCE1); > } > if (TASK2) { > PROGRAM_DO2_body__(&INSTANCE2); > } > } > > What do We see when __tick = greatest_tick_count__? > First. __tick = 0 > Second. Call TASK1 and TASK2. > Third. Invalid period calls TASK1 > > Time diagram: > __tick = 4294967270. Call TASK1 (period = 10 ms) > __tick = 4294967271. Call TASK2 (period = 3 ms) > __tick = 4294967274. Call TASK2 (period = 3 ms) > __tick = 4294967277. Call TASK2 (period = 3 ms) > __tick = 4294967280. Call TASK1 (period = 10 ms) Call TASK2 (period = 3 ms) > > Moment: __tick = greatest_tick_count__ = 4294967281 -> __tick == 0 > > __tick = 0. Call TASK1 (period = 10 ms) Error! Delta TASK1 (10 ms) = 1. > Call TASK2 (period = 3 ms) Error! Delta TASK2 (3 ms) = 1 > > __tick = 3. Call TASK2 (period = 3 ms) > __tick = 6. Call TASK2 (period = 3 ms) > __tick = 9. Call TASK2 (period = 3 ms) > __tick = 10. Call TASK1 (period = 10 ms) > > It's a bag? > > Regards, > > Aleksandr Safronov! > > > ---------------------------------------------------------------------------- > -- Check out the vibrant tech community on one of the world's most > engaging tech sites, Slashdot.org! http://sdm.link/slashdot > _______________________________________________ > Beremiz-devel mailing list > [hidden email] > https://lists.sourceforge.net/lists/listinfo/beremiz-devel ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot _______________________________________________ Beremiz-devel mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/beremiz-devel |
Hi,Mario,
Aleksandr
Why
greatest_tick_count__ is not LCM of all task periods? In case of LCM everythink would work fine... Best regards, Paul Beltyukov 2018-04-09 18:44 GMT+05:00 <[hidden email]>:
------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot _______________________________________________ Beremiz-devel mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/beremiz-devel |
Sorry, Ishould say LCM/GCD instead of LCM. Best regards, Paul Beltyukov 2018-04-10 14:35 GMT+05:00 <[hidden email]>:
------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot _______________________________________________ Beremiz-devel mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/beremiz-devel |
Free forum by Nabble | Edit this page |