John, If you mean adding the current control value to the previous duty-cycle value, then that is effectively a pure integrator, and I think can only result in major instability (almost like using only Integral control). |
Yes the flash of inspiration was pure crap this time, was just thinking it through when you posted it is an integrator.
I have an LED flashing the inverse of the duty cycle! It is not flicking from max to min duty cycle - I know from where my gain is set at what error it will give max duty cycle roughly. I am using integers fudged to make it fractional in places - such as constants. The ADC is 10 bit but I shift it to 8 bits as it is only accurate to +-2LSB, and then I can code everything in bytes. I gather the Link ECU seems to use 8 bit values and copes OK. Then when I multiply the result is an integer. I had to fiddle to keep the signs right. Then I fudge as necessary to sort out the divider for the constants. Quick and dirty but seems accurate enough. I did try FP, but the conversions became a nightmare and I kept ending up with zeros instead of values when converting - the FP library is "experimental" I think and not all the statements support it. I also got caught out by shifting the sign bit along with the rest, but all of this I picked up in simulation. I can get it quite driveable - but I need to add D. [Edited by john banks - 1/19/2002 4:53:42 PM] |
Does the processor have a serial port? If yes, then you could code a data reporting function into the loop. You could make it send out stuff like: in=65, out=5 in=60, out=6 . . . Or whatever, which would help to find out what is happening while driving. You just need a laptop and a terminal program to log the transmitted text. -> Draw a graph, check the dynamics. You are sampling at about 15hz, which gives you about 9600 / 8 / 15 = 80 ascii characters that you can send for each sampling period on a 9600 baud serial link. This will need to be reduced, because some cpu time is needed for your control loop, but you said that you still have about 99% free (and you won't need 80 chars). I think that this would be rather cool... You could post a response curve on here! |
Do you mind us seeing your current controller code, John? Along with how A/D values correspond to boost pressures. It would be interesting to see how you have implemented it. Totally understand if you want to keep it under yer hat though :-) |
It already prints to the RS232 port various data as you will see from the code, but I don't have a laptop! I run it at 19200 baud in simulations and it keeps up fine :)
I have potentiometers on ports 1,2,4&5 of the ADC. TPS goes into port 0, MAP into port 3. The code is in BASIC and commented. It is/will be all open source - I am not making it commercial. [No one else has permission to either]. Dim Setpoint As Byte ' Setpoint Dim Tps As Byte 'throttle position Dim Map As Byte ' MAP Dim Cv As Integer ' output Dim Gain As Integer ' gain Dim Duty As Byte ' target duty cycle if no error Dim X As Word 'temporary unsigned variable for ADC Dim Error As Integer ' Difference between Setpoint and Map Const Psi0 = 116 'ADC input for 0 PSI Const Psi1 = 121 Const Psi2 = 126 Const Psi3 = 131 Const Psi17 = 200 Const Psi18 = 205 Const Psi19 = 210 Const Psi20 = 215 'ADC input for 20 PSI Const Mindutycycle = 0 Const Maxdutycycle = 238 'dutycycle %*2.55 Const Tpstarget = 131 'throttle position reference Config Adc = Single , Prescaler = Auto 'start analog/digital converter Start Adc 'hardware configure 10 bits 0-5V Config Portb = Output Config Timer1 = Pwm , Pwm = 8 , Compare A Pwm = Clear Down , Prescale = 1024 'start PWM output 15.3Hz Enable Interrupts 'each PWM cycle run loop Enable Timer1 On Timer1 Calculate Nosave 'no registers to save Setpoint = Psi17 Do 'endless loop until interrupt Loop Calculate: X = Getadc(0) '10 bits unsigned Shift X , Right , 2 'convert to 8 bit Tps = X 'throttle position X = Getadc(1) '10 bits unsigned Shift X , Right , 2 'convert to 8 bit Duty = X 'target duty cycle if no error X = Getadc(4) Shift X , Right , 2 Gain = X 'gain X = Getadc(3) 'MAP sensor Shift X , Right , 2 Map = X Error = Setpoint - Map Portb = 63 If Error > 0 Then Reset Portb.5 If Error < 3 Then Reset Portb.4 End If If Error < 0 Then Reset Portb.2 If Error > -3 Then Reset Portb.3 End If Cv = Gain * Error Cv = Cv / 128 'kp is in range 0-255 'representing 0-2 therefore divide by 128 'quick and dirty FP math using integers 'not using shifts because signed variable! If Tps < Tpstarget Then Cv = 0 'use static target at partial throttle Cv = Cv + Duty 'error adjust target duty cycle If Map < Psi3 Then Cv = Mindutycycle 'if no boost shut up/rest solenoid If Map > Psi19 Then Cv = Mindutycycle 'overboost cutout for momentary 20PSI If Cv < Mindutycycle Then Cv = Mindutycycle 'check and correct out of bounds If Cv > Maxdutycycle Then Cv = Maxdutycycle Pwm1a = Cv 'adjust duty cycle output Print "TPS " ; Tps ; " TPS target " ; Tpstarget ; " Duty " ; Duty ; " Target " ; Setpoint ; " Gain " ; Gain ; " Actual " ; Map ; " Output " ; Cv 'print data to RS232 port if present Return |
Oh bugger, I'm not used to BASIC! More at home with C. Got to go and see my girlfriend tonight, but will study in detail tomorrow! BTW. How big are those integer variables (16 bit)? And I guess they are signed by default?? Are the byte ones signed etc. Got to go... |
Integers signed 16 bit. Bytes not.
BTW IT WORKS! Using PD gives fantastic boost control. Will post more after some well earned food. Absolutely ballistic spool up with sufficient throttle. No peaks. |
You clever buggers. I am currently studying for a BEng hons in Instrumentation. Sounds like you guys might be able to help in the future. Could be good project for me. (not yet)
|
WHEN?
|
I am talking months away for a project that I am going to have to do! Dont know what has to be involved yet but sound good idea combining Instrument/Electronic knowledge with an outside interest (Impreza's).
I am in 3rd year of 6 year part time degree btw. I see in your other thread you wanted input from Process/Control Engineers. I am a Instrument Technician (same sort of thing) but I feel that I cant help you further. Your already going beyond my curent knowledge! I have access to test equipment though, or possible really brainy boffs at uni. Give us an email if I could assist, but as above probably more the other way round. Cheers Stuart [Edited by stuart12 - 1/23/2002 12:34:40 AM] |
All times are GMT +1. The time now is 10:46 AM. |
© 2024 MH Sub I, LLC dba Internet Brands