Question about momentary switch

Support forum for users of the M1 Build

Question about momentary switch

Postby junnan yue on Fri Oct 12, 2018 2:41 am

Hi guys
I have a 3 position momentary switch in my car,and what i want is use that switch to control the Launch Engine Speed Aim table,so is like every time flip the switch up and the Launch Engine Speed Aim table goes up one number. And Down just like how Up works.

However I do create the code and load in to the ECU. But turn out as soon as I flip the switch the number just go to the maximum.

Please help with this, what I should do to make this function to work just like PDM Counter function, the number just increase one number at a time.

Thanks a lot!
Attachments
Capture33.JPG
Capture33.JPG (16.97 KiB) Viewed 6717 times
junnan yue
 
Posts: 33
Joined: Thu May 30, 2013 6:09 pm

Re: Question about momentary switch

Postby rntechnologies on Fri Oct 12, 2018 8:41 am

There are a couple of ways to achieve this result, however without seeing the rest of your code its difficult to definitively say what the correct way is for you.
The code that you have written is fundamentally correct, however there are a few things to be careful of:

1. If the code execution rate is set pretty quick, you could have a case where in the time that it takes you to flick the switch to the on position and let it go, the code may have executed a number of times. You should perform a check in your code to check the last state of the switch, and only increment the number on the change event of the switch.

2. Are you setting up the switch to ensure that it operates in the same manner as a driver rotary switch? Ultimately you need to ensure that your switch is behaving in the same way as the rotary switch within your code. Then in tune you need to map the position (voltage, or in your case, emulated voltage) to the differing switch positions?

Nb. you can shorten up your code on the count by using: 'val += 1' rather than 'val = val + 1' and the same for 'val -= 1'.

Cheers,
Ryan
Regards,
Ryan
Powertune Australia
rntechnologies
Pro User
 
Posts: 91
Joined: Tue Aug 07, 2018 9:45 am
Location: Sydney, Australia

Re: Question about momentary switch

Postby AlanB on Fri Oct 12, 2018 6:30 pm

Here is a bit of code I use for a traction control trim. It is based on two momentary switches (up and down) and counts between minus 5 (-5) and plus 5 (+5). The final value is also flash backed. You should be able to modify this to give you the behaviour you want. Note the use of Change.To when detecting the switch state change.
Attachments
TractionTrimCalc.JPG
TractionTrimCalc.JPG (74.35 KiB) Viewed 6701 times
Alan Bell
MoTeC Europe Ltd
User avatar
AlanB
 
Posts: 104
Joined: Tue May 20, 2008 11:25 pm


Return to M1 Build

Who is online

Users browsing this forum: No registered users and 4 guests