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.