Can I use a large lookup table in PBasic?
MCRlabs
Posts: 3
I am a mechanical engineering who works in the Detroit Automotive Industry. I do well with mechanical stuff, but I am just an eager microcontroller student with little experience at this point.
I am currently trying to design a throttle pedal simulator using my basic stamp. This throttle pedal simulator will be used to replace a drive-by-wire throttle pedal that is used commonly in a modern vehicle. As you may already know, a modern throttle pedal is no longer directly connected to the throttle blade like it was in the good ole days ..Rather, a modern throttle pedal is simply a 2 channel analog potentiometer in most cases. Your throttle pedal simply sends two analog voltages to your PCM (Powertrain Control Module). Your PCM then uses these two voltages to determine the desired throttle % and control the actual throttle blade angle. The voltage outputs from the throttle pedal can be characterized by two linear functions. Usually one has a positive slope while the other commonly has a negative slope. I want to use this throttle pedal simulator in my dynamometer test laboratory so that I can have better control over demanded thorttle angle, as well as program smoth transient throttle sweeps.
I have recently been working the What is a Microcontroller textbook and am learning how to use an AD5220 potentiometer IC chip. I have also looked ahead in the Basic Analog to Digital textbook to learn how to use an ADC0831 ADC IC chip. I would like to combine my knowledge of these devices to make my throttle pedal simulator. I would like to use the ADC0831 chip to acquire a 0-5volt user input which will be used to determine the requested throttle pedal from the test cell 0volts = closed throttle, 5volts = wide open. After acquiring the user request I would like to adjust 2 independent AD5220 potentiometer IC chips to mimic the 2 channel potentiometer common to an actual throttle pedal found in a real vehicle.
I believe I can easily learn how to use the ADC0831and the AD5220 chips for this application by recycling some of my existing practice code from the textbooks exercises I have already done. Of course some modification and creativity will be needed as well was some classy organization of subroutines and passing variables among each routine will be needed, but I think I can work through most of that myself .The one thing that is currently confusing me is trying figure out if my basic stamp is capable of using a large look up table, and if it is, how do I set it up?
Basically, I would like to interrogate the ADC0831 chip with my basic stamp to acquire the user request. I then want to take the user request to a look up table and find the row of the look up table that is closest to the recently acquired user request. Each row of the lookup table will include 1 requested value and 2 Tap# values that will be calibrated to provide the correct voltage output for each potentiometer channel in such a way that the PCM will think it is getting signals from a real throttle pedal (the output voltage functions will match an actual vehicle pedal). An example of this table can be seen below.
The table I would like to use would probably have 128 discrete points to match the number of possible outputs from the AD5220 chip. I desire to use an open loop control table because 128 stable and discrete outputs would work exceptionally well for this application. Closed loop control would be unnecessary and possibly provide some instability for intermediate points between possible AD5220 settings. You may also suggest that I keep it simple by dropping the AD5220 chip and us a mock PWM analog output instead, but I have been advised against this since this type of noisy signal may cause some instability.
Sorry for being long winded, but is it possible to have the basic stamp handle a large look up table like I have described, and if so, are there any good examples or text references on how to correctly set up large look up tables .Also, do I need to do anything special to locate the next closest input value common to my lookup table instead of looking for the exact input value which may not be present on my look up table. i.e. my ADC0831 will have a higher resolution than the 128 steps on my look up table. If my user requested value is 1.268 volts, do I need to do anything to force my input up or down to the next closest value that actually exists on my look up table?
Thanks
I am currently trying to design a throttle pedal simulator using my basic stamp. This throttle pedal simulator will be used to replace a drive-by-wire throttle pedal that is used commonly in a modern vehicle. As you may already know, a modern throttle pedal is no longer directly connected to the throttle blade like it was in the good ole days ..Rather, a modern throttle pedal is simply a 2 channel analog potentiometer in most cases. Your throttle pedal simply sends two analog voltages to your PCM (Powertrain Control Module). Your PCM then uses these two voltages to determine the desired throttle % and control the actual throttle blade angle. The voltage outputs from the throttle pedal can be characterized by two linear functions. Usually one has a positive slope while the other commonly has a negative slope. I want to use this throttle pedal simulator in my dynamometer test laboratory so that I can have better control over demanded thorttle angle, as well as program smoth transient throttle sweeps.
I have recently been working the What is a Microcontroller textbook and am learning how to use an AD5220 potentiometer IC chip. I have also looked ahead in the Basic Analog to Digital textbook to learn how to use an ADC0831 ADC IC chip. I would like to combine my knowledge of these devices to make my throttle pedal simulator. I would like to use the ADC0831 chip to acquire a 0-5volt user input which will be used to determine the requested throttle pedal from the test cell 0volts = closed throttle, 5volts = wide open. After acquiring the user request I would like to adjust 2 independent AD5220 potentiometer IC chips to mimic the 2 channel potentiometer common to an actual throttle pedal found in a real vehicle.
I believe I can easily learn how to use the ADC0831and the AD5220 chips for this application by recycling some of my existing practice code from the textbooks exercises I have already done. Of course some modification and creativity will be needed as well was some classy organization of subroutines and passing variables among each routine will be needed, but I think I can work through most of that myself .The one thing that is currently confusing me is trying figure out if my basic stamp is capable of using a large look up table, and if it is, how do I set it up?
Basically, I would like to interrogate the ADC0831 chip with my basic stamp to acquire the user request. I then want to take the user request to a look up table and find the row of the look up table that is closest to the recently acquired user request. Each row of the lookup table will include 1 requested value and 2 Tap# values that will be calibrated to provide the correct voltage output for each potentiometer channel in such a way that the PCM will think it is getting signals from a real throttle pedal (the output voltage functions will match an actual vehicle pedal). An example of this table can be seen below.
ADC0831 (user request)
Channel 1 AD5220 (Tap #)
Channel 2 AD5220 (Tap #)
0 (8 bit binary #)
127
1 (8 bit binary #)
103
26
2 (8 bit binary #)
77
51
3 (8 bit binary #)
51
77
4 (8 bit binary #)
26
103
5 (8 bit binary #)
127
The table I would like to use would probably have 128 discrete points to match the number of possible outputs from the AD5220 chip. I desire to use an open loop control table because 128 stable and discrete outputs would work exceptionally well for this application. Closed loop control would be unnecessary and possibly provide some instability for intermediate points between possible AD5220 settings. You may also suggest that I keep it simple by dropping the AD5220 chip and us a mock PWM analog output instead, but I have been advised against this since this type of noisy signal may cause some instability.
Sorry for being long winded, but is it possible to have the basic stamp handle a large look up table like I have described, and if so, are there any good examples or text references on how to correctly set up large look up tables .Also, do I need to do anything special to locate the next closest input value common to my lookup table instead of looking for the exact input value which may not be present on my look up table. i.e. my ADC0831 will have a higher resolution than the 128 steps on my look up table. If my user requested value is 1.268 volts, do I need to do anything to force my input up or down to the next closest value that actually exists on my look up table?
Thanks
Comments
Don't apologize for being "long winded" - it's refreshing to see such a detailed explanation of a request. :thumb:
My first reaction to your requirements would be to review the DATA and/or LOOKUP/LOOKDOWN PBasic statements.
DATA allows you to preload memory locations in the EEPROM that can be referenced by the Stamp.
LOOKUP/LOOKDOWN may offer some use, but I don't know the size limitations of the statement's arguments.
I'm sure the resident Forum Wizards will chime in shortly.
*8)
result1 will be your first pot setting. Repeat with another LOOKUP for result2 for the second pot setting.
adcval is the reading from your ADC, and it's divided by 2 to limit your table to 128 entries.
Now be sure to add a kill switch in case your ADC gets stuck... we don't want any runaway test vehicles!
OOOH....the LOOKUP command looks like just the thing I need....Thanks for the tip. I do have a question about dividing the INDEX value by 2 though. It appears that the INDEX value in the LOOKUP command (adcval) can only be a whole number interger between 0 and 255. If my raw adcval was 254 and then I divided it by 2, then the LOOKUP command would go the 127th index position in my value list and put whatever number I have in this postion into the ouput variable...but if my raw adcval was 251, or any other odd number, would the LOOKUP command try to find the 125.5th index postion and then freakout and crash because the 125.5th index position does not exist?
Does this make sense, or am I not thinking about this command correctly?
You can write a simple test program that demonstrates this by counting from 0 through 255 and diving the current index by 2 and displaying that value on the DEBUG screen.
Don't worry Sapphire, we won't have any runaway vehicles...The engines I test have been removed from the vehicle and are mounted to a stationary dynamometer. If my rookie coding inadvertently creates an accidental WOT command (Wide Open Throttle)...We just smash a big red E-Stop button on the test consol and it kills V-power to the PCM and turns off the fuel supply and pump....Such a thing will make any modern engine stop running "RIGHT-NOW!!!"
Thanks for your help, I will post my creation once I work out the bugs and get it functional....I am sure I will probably have at least 1 more question or problem along the way anyhow.
This BASIC-stamp thingy is pretty cool ehh! I wish I would have found it many years ago at the beginning of my mechanical engineering career. Looking back, I know I could have used it for many other simple tasks similar to this.
Chris answered your question about odd numbers, so you should be good. It will always find something in the LOOKUP unless the aren't enough entries, in which case result is unchanged.
We'd love to see your final project... it sounds very interesting. Ask if you have more questions!