Closed Mynogs closed 5 years ago
if what == 'GENERATOR_MAIN' then
return [[
do
print('Start p+ simulation ' .. (sim.stepRateS * 1000) .. 'ms cycle time')
local t = tmr.attach(
sim.stepRateS * 1000,
function()
block.step()
collectgarbage()
sim.step = sim.step + 1
sim.stepT0 = sim.stepT0 + 1
sim.timeS = sim.timeS + sim.stepRateS
end
)
t:start()
end
]]
@Mynogs,
You missed to set which timer hardware to use. An example is as follows:
t = tmr.attach(
tmr.TMR0,
1000 * 50,
function()
print("hi")
end
)
t:start()
Review the attach's signature in the wiki:
I tryed to use the software timer. Now I chanced it:
do
print('Start p+ simulation ' .. (sim.stepRateS * 1000) .. 'ms cycle time')
local t = tmr.attach(
tmr.TMR0,
sim.stepRateS * 1000000,
function()
block.step()
collectgarbage()
sim.step = sim.step + 1
sim.stepT0 = sim.stepT0 + 1
sim.timeS = sim.timeS + sim.stepRateS
end
)
t:start()
end
The timer still fired only once and the board no longer react to ctrl-c! I must press the reset button. It is correct to end the Lua program? Or must I go to some kind of idle loop?
@Mynogs,
In your tests, which is the value for sim.stepRateS?
@Mynogs,
Not feedback about the value for sim.stepRateS. Please, reopen in case you need more assistance.
@jolivepetrus Sorry I missed your question! The value of sim.simStepS is 0.1 This means calculate a simulation step ever 100ms.
This is part of the p+ simulation system (Simulink like). This part execute the main simulation block. But the timer fires only one. What's wong with my code?
do print('Start p+ simulation ' .. (sim.stepRateS 1000) .. 'ms cycle time') local t = tmr.attach( sim.stepRateS 1000, function()
block.step() collectgarbage() sim.step = sim.step + 1 sim.stepT0 = sim.stepT0 + 1 sim.timeS = sim.timeS + sim.stepRateS end ) t:start() end ]] end