Re: Can the GPIO run variable cam phasing?
Posted: Mon Apr 06, 2009 9:38 am
Okay, now that we have the initial thoughts out of the way, we'll add the variables to the INI and code, and sketch out the 'pseudo-code'. (Pseudo-code is term term meant to imply that the code is logically correct, but may not have all the proper syntax, etc. to become running code. It is used as a guide when writing the functional code.)
In the global variables section, under 'int refresh_counter;' we added earlier, we add:
This adds the output1/2 PWM counter. This doesn't need to be added to the INI, it is entirely internal (but note that we can view it by setting outpc.dbug = out12_pwm_count;).
However, we also need to add the PWM parameters to the code and INI. In the code, the parameters are add to the inpram. structure so MegaTune can see them:
becomes:
we also need to add the default values:
Then we add these to the INI:
becomes:
and change the page size to match:
Finally, we add the parameters to a menu:
Compile the code, load it, and open MegaTune. If all that happens without errors, we are ready to write some (pseudo) code! We'll do that in the next post.
Lance.
In the global variables section, under 'int refresh_counter;' we added earlier, we add:
Code: Select all
unsigned int out12_pwm_count; // output1 and output2 counter (in 0.128 clock tics)
However, we also need to add the PWM parameters to the code and INI. In the code, the parameters are add to the inpram. structure so MegaTune can see them:
Code: Select all
typedef struct {
...
unsigned int refresh_int; // the interval time (msec) between dithers for output1 and output2
unsigned int refresh_dur; // the 100% duty cycle time for output1 and output2
unsigned int dither_intPC; // the interval time (msec) between dithers for the pressure control output
unsigned int dither_durPC; // the 100% duty cycle time for the pressure control output
} inputs1;
Code: Select all
typedef struct {
...
unsigned int refresh_int; // the interval time (msec) between dithers for output1 and output2
unsigned int refresh_dur; // the 100% duty cycle time for output1 and output2
unsigned int dither_intPC; // the interval time (msec) between dithers for the pressure control output
unsigned int dither_durPC; // the 100% duty cycle time for the pressure control output
unsigned char out12_pwm_off; // output1 and output2 off duration (in 0.128 clock tics)
unsigned char out12_pwm_on; // output1 and output2 on duration (in 0.128 clock tics)
} inputs1;
Code: Select all
50, // PWM refresh interval (msec)
8, // PWM refresh duration (msec)
10000, // PC dither interval (msec)
1000, // PC dither duration (msec)
0, // output1 and output2 off duration (in 0.128 clock tics)
100, // output1 and output2 on duration (in 0.128 clock tics)
};
Code: Select all
refresh_int = scalar, U16, 538, "msec", 1.00, 0.0000, 10, 20000, 0 ; the interval time (msec) between dithers for output1 and output2
refresh_dur = scalar, U16, 540, "msec", 1.00, 0.0000, 0, 10000, 0 ; the 100% duty cycle time for output1 and output2
dither_intPC = scalar, U16, 542, "msec", 1.00, 0.0000, 10, 20000, 0 ; the interval time (msec) between dithers for the pressure control output
dither_durPC = scalar, U16, 544, "msec", 1.00, 0.0000, 0, 10000, 0 ; the 100% duty cycle time for the pressure control output
; ****************************************************************** end inpram *********************
; pageSize = 544 + 2 = 546 (= 222 hex) bytes
Code: Select all
refresh_int = scalar, U16, 538, "msec", 1.00, 0.0000, 10, 20000, 0 ; the interval time (msec) between dithers for output1 and output2
refresh_dur = scalar, U16, 540, "msec", 1.00, 0.0000, 0, 10000, 0 ; the 100% duty cycle time for output1 and output2
dither_intPC = scalar, U16, 542, "msec", 1.00, 0.0000, 10, 20000, 0 ; the interval time (msec) between dithers for the pressure control output
dither_durPC = scalar, U16, 544, "msec", 1.00, 0.0000, 0, 10000, 0 ; the 100% duty cycle time for the pressure control output
out12_pwm_off = scalar, U08, 546, "msec", 0.128, 0.0000, 0, 32.64, 3 ; output1 and output2 off duration (in 0.128 clock tics)
out12_pwm_on = scalar, U08, 547, "msec", 0.128, 0.0000, 0, 32.64, 3 ; output1 and output2 on duration (in 0.128 clock tics)
; ****************************************************************** end inpram *********************
; pageSize = 547 + 1 = 548 (= 224 hex) bytes
Code: Select all
pageSize = 548, 30
Code: Select all
dialog = PWMSettings, "Solenoid PWM Setup"
field = "TCC PWM Period", TCC_PWM_Pd
field = "PC PWM Period", PC_PWM_Pd
field = "PC Voltage Correction", BatFac
field = "Output3 PWM Period", SOL32_PWM_Pd
field = "Output1/2 ON Period", out12_pwm_on
field = "Output1/2 OFF Period", out12_pwm_off
Lance.