View previous topic :: View next topic |
Author |
Message |
rayhall
Joined: 28 May 2006 Posts: 130
|
Posted: Sun Jan 27, 2008 11:29 pm Post subject: Bug in compiler or in me? |
|
|
The first code works and the correct values are passed to the Dbw_pid sub. The second seems to be getting very low or zero values. I cannot see why.
I am using the Mega2561, and compiler version 1.11.9.0
Thanks
Ray.
Code: | Dim Running As Bit
Dim Rpm As Word 'Engine RPM
Dim Tps_main As Integer 'Foot pedal main signal
Dim Tps_sub As Integer 'Foot pedal sub signal
Dim Tb As Integer 'Throttle body position
Dim Tps As Integer 'Foot pedal position
Dim Idle_offset As Integer 'Idle rpm offset
'{---------------------- Timer0 --------------------------}
Timer_0:
Tps_main = Getadc(0) 'Pedal throttle position main signal
Tps_sub = Getadc(1) 'Pedal throttle position sub signal
Tps = Tps_main + Tps_sub
Tps = Tps / 2 'Calculate the average of both signals
Tb = Getadc(2) 'Throttle body position main signal
If Running = True Then 'If engine running
If Tps < Idle_limit And Rpm < 1500 And Fastidle = False Then
Tps = Tps + Idle_offset
End If
If Ac_on = True And Tps < Idle_limit Then 'If AC on, then add offset
Tb = Tb - Ac_offset_val
End If
Call Dbw_pid(tps , Tb) 'Call throttle motor control PID
Else 'If engine not running
Call Dbw_pid(tps , Tb) 'Call throttle motor control PID
End If
Return |
Code: | Dim Running As Bit
Dim Rpm As Word 'Engine RPM
Dim Tps_main As Integer 'Foot pedal main signal
Dim Tps_sub As Integer 'Foot pedal sub signal
Dim Tb As Integer 'Throttle body position
Dim Tb_t As Integer 'Throttle body temp position
Dim Tps As Integer 'Foot pedal position
Dim Tps_t As Integer 'Foot pedal temp position
Dim Idle_offset As Integer 'Idle rpm offset
'{---------------------- Timer0 --------------------------}
Timer_0:
Tps_main = Getadc(0) 'Pedal throttle position main signal
Tps_sub = Getadc(1) 'Pedal throttle position sub signal
Tps = Tps_main + Tps_sub
Tps = Tps / 2 'Calculate the average of both signals
Tb = Getadc(2) 'Throttle body position main signal
If Running = True Then 'If engine running
If Tps < Idle_limit And Rpm < 1500 And Fastidle = False Then
Tps_t = Tps + Idle_offset
Tb_t = Tb
End If
If Ac_on = True And Tps < Idle_limit Then 'If AC on, then add offset
Tb_t = Tb - Ac_offset_val
Tps_t = Tps
End If
Call Dbw_pid(tps_t , Tb_t) 'Call throttle motor control PID
Else 'If engine not running
Call Dbw_pid(tps , Tb) 'Call throttle motor control PID
End If
Return |
|
|
Back to top |
|
|
ZOHAIB
Joined: 11 Sep 2007 Posts: 58
|
Posted: Mon Jan 28, 2008 10:33 am Post subject: |
|
|
hi!
dont declare the variable which are storing adc value as integer declare them as word
regards |
|
Back to top |
|
|
Luciano
Joined: 29 Nov 2004 Posts: 3149 Location: Italy
|
Posted: Mon Jan 28, 2008 10:37 am Post subject: |
|
|
Hi Ray,
What are the used stack values?
Code: | $hwstack = ??
$swstack = ??
$framesize = ?? |
Best regards,
Luciano |
|
Back to top |
|
|
for_ro
Joined: 11 Nov 2007 Posts: 260
|
Posted: Mon Jan 28, 2008 4:35 pm Post subject: |
|
|
Hi,
there is a slight change in your code as well.
In the top code, tps and tb are always set to ADC values and handed over to the Dbw_pid function
In the second code, the arguments of the function (tps_t and tb_t ) are only set, if tps < idle_limit. Otherwise they will remain on 0.
Only if the engine is not Running (Running=True) the function is directly called with tps and tb.
Additionally I wouldn't do that much calculation in the Timer0 ISR.
Regards
Rolf |
|
Back to top |
|
|
rayhall
Joined: 28 May 2006 Posts: 130
|
Posted: Thu Jan 31, 2008 11:03 am Post subject: |
|
|
Luciano,
This is what I am using.
$hwstack = 512
$swstack = 512
$framesize = 512
Ray. |
|
Back to top |
|
|
rayhall
Joined: 28 May 2006 Posts: 130
|
Posted: Sat Feb 02, 2008 8:00 am Post subject: |
|
|
Rolf,
Thank you..You were correct. Adding this made sure they did not have zero values
Tb_t = Tb
Tps_t = Tps
This is the code fixed.
Code: | Dim Running As Bit
Dim Rpm As Word 'Engine RPM
Dim Tps_main As Integer 'Foot pedal main signal
Dim Tps_sub As Integer 'Foot pedal sub signal
Dim Tb As Integer 'Throttle body position
Dim Tb_t As Integer 'Throttle body temp position
Dim Tps As Integer 'Foot pedal position
Dim Tps_t As Integer 'Foot pedal temp position
Dim Idle_offset As Integer 'Idle rpm offset
'{---------------------- Timer0 --------------------------}
Timer_0:
Tps_main = Getadc(0) 'Pedal throttle position main signal
Tps_sub = Getadc(1) 'Pedal throttle position sub signal
Tps = Tps_main + Tps_sub
Tps = Tps / 2 'Calculate the average of both signals
Tb = Getadc(2) 'Throttle body position main signal
Tb_t = Tb '********
Tps_t = Tps '*******
If Running = True Then 'If engine running
If Tps < Idle_limit And Rpm < 1500 And Fastidle = False Then
Tps_t = Tps + Idle_offset
Tb_t = Tb
End If
If Ac_on = True And Tps < Idle_limit Then 'If AC on, then add offset
Tb_t = Tb - Ac_offset_val
Tps_t = Tps
End If
Call Dbw_pid(tps_t , Tb_t) 'Call throttle motor control PID
Else 'If engine not running
Call Dbw_pid(tps , Tb) 'Call throttle motor control PID
End If
Return |
|
|
Back to top |
|
|
|