|
@@ -8,14 +8,14 @@
|
|
|
|
|
|
|
|
|
out_t outputs[DO_NUMBER] = {
|
|
|
- {GPIOC, GPIO_PINS_12, 0}, // -
|
|
|
- {GPIOD, GPIO_PINS_2, 0}, // -
|
|
|
- {GPIOE, GPIO_PINS_6, 0}, // TMR9_CH2 (remap)
|
|
|
- {GPIOC, GPIO_PINS_1, 0}, // -
|
|
|
- {GPIOC, GPIO_PINS_11, 0}, // -
|
|
|
- {GPIOD, GPIO_PINS_3, 0}, // -
|
|
|
- {GPIOE, GPIO_PINS_5, 0}, // TMR9_CH1 (remap)
|
|
|
- {GPIOC, GPIO_PINS_2, 0} // -
|
|
|
+ {GPIOC, GPIO_PINS_12, 0, 0, 0}, // -
|
|
|
+ {GPIOD, GPIO_PINS_2, 0, 0, 0}, // -
|
|
|
+ {GPIOE, GPIO_PINS_6, 0, 0, 0}, // TMR9_CH2 (remap)
|
|
|
+ {GPIOC, GPIO_PINS_1, 0, 0, 0}, // -
|
|
|
+ {GPIOC, GPIO_PINS_11, 0, 0, 0}, // -
|
|
|
+ {GPIOD, GPIO_PINS_3, 0, 0, 0}, // -
|
|
|
+ {GPIOE, GPIO_PINS_5, 0, 0, 0}, // TMR9_CH1 (remap)
|
|
|
+ {GPIOC, GPIO_PINS_2, 0, 0, 0} // -
|
|
|
};
|
|
|
|
|
|
|
|
@@ -101,9 +101,32 @@ void do_update(out_t *out, uint8_t index)
|
|
|
}
|
|
|
|
|
|
//
|
|
|
+void do_set_mode(void)
|
|
|
+{
|
|
|
+ if (output_mode_bit == settings.do_mode_bits)
|
|
|
+ return;
|
|
|
+
|
|
|
+ // Состояние выхода/выходов изменилось
|
|
|
+ for (int i = 0; i < DO_NUMBER; i++)
|
|
|
+ {
|
|
|
+ if ((settings.do_mode_bits & (1 << i)) != (output_mode_bit & (1 << i)))
|
|
|
+ {
|
|
|
+ settings.do_mode_bits |= (1 << i);
|
|
|
+ do_update(&outputs[i], i);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ settings.do_mode_bits = output_mode_bit;
|
|
|
+}
|
|
|
+
|
|
|
+//#define PWM_PERIOD_TEST 20
|
|
|
+//#define PWM_DUTY_TEST 10
|
|
|
void do_set_pwm(uint16_t pwm, uint8_t index)
|
|
|
{
|
|
|
- // pass
|
|
|
+ //outputs[index].pwm_duty_cnt = (uint16_t)(outputs[index].pwm_period_cnt*pwm/100.0);
|
|
|
+ outputs[index].pwm_duty_cnt = (uint16_t)(PWM_PERIOD_TEST*pwm/100.0);
|
|
|
+ outputs[index].mode = 1;
|
|
|
+
|
|
|
}
|
|
|
|
|
|
//
|
|
@@ -154,6 +177,64 @@ void out_as_pwm(void)
|
|
|
tmr_counter_enable(TMR9, TRUE);
|
|
|
}
|
|
|
|
|
|
+// Таймер для выходов в режиме PWM. Частота 10Гц.
|
|
|
+void out_pwm_tim_init(void)
|
|
|
+{
|
|
|
+ uint16_t prescaler_value = 0;
|
|
|
+ uint16_t timer_period = 1000 - 1;
|
|
|
+ gpio_init_type gpio_init_struct;
|
|
|
+
|
|
|
+ gpio_default_para_init(&gpio_init_struct);
|
|
|
+
|
|
|
+ gpio_init_struct.gpio_pins = GPIO_PINS_15;
|
|
|
+ gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
|
|
|
+ gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
|
|
|
+ gpio_init_struct.gpio_mode = GPIO_MODE_OUTPUT;
|
|
|
+ gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_STRONGER;
|
|
|
+ gpio_init(GPIOB, &gpio_init_struct);
|
|
|
+
|
|
|
+ crm_periph_clock_enable(CRM_TMR9_PERIPH_CLOCK, TRUE);
|
|
|
+
|
|
|
+ prescaler_value = (uint16_t)(system_core_clock / 10000) - 1;
|
|
|
+ tmr_base_init(TMR9, timer_period, prescaler_value);
|
|
|
+
|
|
|
+ tmr_cnt_dir_set(TMR9, TMR_COUNT_UP);
|
|
|
+ tmr_clock_source_div_set(TMR9, TMR_CLOCK_DIV1);
|
|
|
+
|
|
|
+ nvic_irq_enable(TMR1_BRK_TMR9_IRQn, 5, 0);
|
|
|
+
|
|
|
+ tmr_interrupt_enable(TMR9, TMR_OVF_INT, TRUE);
|
|
|
+
|
|
|
+ tmr_counter_enable(TMR9, TRUE);
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+inline void pwm_proc(void)
|
|
|
+{
|
|
|
+ for (int i = 0; i < DO_NUMBER; i++)
|
|
|
+ {
|
|
|
+ if (outputs[i].mode) // режим PWM
|
|
|
+ {
|
|
|
+ outputs[i].pwm_period_cnt++;
|
|
|
+ outputs[i].pwm_duty_cnt++;
|
|
|
+
|
|
|
+ if (outputs[i].pwm_period_cnt == PWM_PERIOD_TEST)
|
|
|
+ {
|
|
|
+ outputs[i].pwm_period_cnt = 0;
|
|
|
+ gpio_bits_set(GPIOB, GPIO_PINS_15);
|
|
|
+ }
|
|
|
+ else if (outputs[i].pwm_duty_cnt == PWM_DUTY_TEST)
|
|
|
+ {
|
|
|
+ outputs[i].pwm_duty_cnt = 0;
|
|
|
+ gpio_bits_reset(GPIOB, GPIO_PINS_15);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
//
|
|
|
void load_sens_init(simple_gpio_t *sens)
|
|
|
{
|
|
@@ -190,7 +271,18 @@ void out_test(void)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+//
|
|
|
+void TMR1_BRK_TMR9_IRQHandler(void)
|
|
|
+{
|
|
|
+ if(tmr_flag_get(TMR9, TMR_OVF_FLAG) != RESET)
|
|
|
+ {
|
|
|
+ tmr_flag_clear(TMR9, TMR_OVF_FLAG);
|
|
|
+ //GPIOB->odt ^= GPIO_PINS_15;
|
|
|
+ pwm_proc();
|
|
|
+ }
|
|
|
+}
|
|
|
|
|
|
+#if 0
|
|
|
void TMR1_BRK_TMR9_IRQHandler(void)
|
|
|
{
|
|
|
static uint32_t cnt1 = 0;
|
|
@@ -209,3 +301,4 @@ void TMR1_BRK_TMR9_IRQHandler(void)
|
|
|
printf("Cnt2 %u\r\n", cnt2);
|
|
|
}
|
|
|
}
|
|
|
+#endif
|