Skip to content

Latest commit

 

History

History
51 lines (37 loc) · 1.91 KB

lua.md

File metadata and controls

51 lines (37 loc) · 1.91 KB

Lua on rusEFI Proteus

As of 2021 rusEFI uses a popular open source Lua scripting engine, see rusEFI documentation

Some ECUs (EGS, ABS/ASC/MSR) in my BMW 8-series need a PWM (100Hz) modulated throttle position signal to work error free. Lua gives us the possibility to realize it

How is Lua configured now? Here are the necessary steps

  • assign output
  • set PWM frequency and initial duty cycle
  • update duty cycle in event

Assign Lua output, go for "Advanced" -> "Lua Script PWM Outputs"

alt text

set PWM frequency and initial duty cycle

startPwm(0, 100, 0) -- starts PWM on output #0 (check TunerStudio) with 100Hz and initial duty cycle of 0%

update duty cycle in event

function onTick()
    local pedalPosition = getSensor("AcceleratorPedal") -- get actual value of AcceleratorPedal, should by between 0 and 100
    pedalPosition = (pedalPosition == nil and 'invalid pedalPosition' or pedalPosition)
    local pwmValue = pedalPosition / 100
    setPwmDuty(0, pwmValue) -- set duty cycle. the correct value is between 0 (= 0%) and 1 (100%)
    print('pedal position: ' .. pedalPosition .. ' duty cycle ' .. pwmValue) -- do some output
    print('')
end

Whole code

startPwm(0, 100, 0) -- starts PWM on output #0 (check TunerStudio) with 100Hz and initial duty cycle o 0%

function onTick()
    local pedalPosition = getSensor("AcceleratorPedal") -- get actual value of AcceleratorPedal, should by between 0 and 100
    pedalPosition = (pedalPosition == nil and 'invalid pedalPosition' or pedalPosition)
    local pwmValue = pedalPosition / 100
    setPwmDuty(0, pwmValue) -- set duty cycle. the correct value is between 0 (= 0%) and 1 (100%)
    print('pedal position: ' .. pedalPosition .. ' duty cycle ' .. pwmValue) -- do some output
    print('')
end