Test working at 100Khz
This commit is contained in:
@@ -1,119 +1,156 @@
|
||||
#include "timer.h"
|
||||
|
||||
#define TIME_CONST 1
|
||||
|
||||
enum State {
|
||||
S_12P,
|
||||
S_12N_DELAY,
|
||||
S_12N,
|
||||
S_WAIT_10MS,
|
||||
S_34P,
|
||||
S_34N_DELAY,
|
||||
S_34N,
|
||||
S_WAIT_1MS,
|
||||
S_WAIT_10MS_END
|
||||
};
|
||||
|
||||
volatile State state = S_12P;
|
||||
volatile uint32_t state_time = 0;
|
||||
|
||||
void onTimer(void* arg) {
|
||||
volatile static bool wait_sent = false;
|
||||
|
||||
void onTimer(void *arg)
|
||||
{
|
||||
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
|
||||
TaskHandle_t task = (TaskHandle_t)(arg);
|
||||
state_time += 1;
|
||||
timerStatus *params = (timerStatus *)(arg);
|
||||
TaskHandle_t task = params->main_task;
|
||||
|
||||
switch (state) {
|
||||
// increment state time
|
||||
params->state_time += params->clock_period_us;
|
||||
|
||||
digitalWrite(PIN_TRIG_B12P, HIGH);
|
||||
|
||||
switch (params->state)
|
||||
{
|
||||
|
||||
case S_12P:
|
||||
digitalWrite(PIN_TRIG_A12P, HIGH);
|
||||
xTaskNotifyFromISR(task, PIN_TRIG_A12P, eSetValueWithOverwrite, &xHigherPriorityTaskWoken);
|
||||
if (params->state_time == params->clock_period_us && !params->coil12p_high)
|
||||
{
|
||||
//xTaskNotifyFromISR(task, PIN_TRIG_A12P, eSetValueWithOverwrite, &xHigherPriorityTaskWoken);
|
||||
digitalWrite(PIN_TRIG_A12P, HIGH);
|
||||
params->coil12p_high = true;
|
||||
wait_sent = false;
|
||||
}
|
||||
|
||||
if (state_time == 2*TIME_CONST){
|
||||
xTaskNotifyFromISR(task, SPARK_A12, eSetValueWithOverwrite, &xHigherPriorityTaskWoken);
|
||||
if (params->state_time == params->spark_delay_us)
|
||||
{
|
||||
//xTaskNotifyFromISR(task, SPARK_A12, eSetValueWithOverwrite, &xHigherPriorityTaskWoken);
|
||||
digitalWrite(SPARK_A12, HIGH);
|
||||
}
|
||||
|
||||
if (state_time == 7*TIME_CONST) {
|
||||
xTaskNotifyFromISR(task, ~SPARK_A12, eSetValueWithOverwrite, &xHigherPriorityTaskWoken);
|
||||
if (params->state_time >= params->coil_pulse_us && params->coil12p_high)
|
||||
{
|
||||
//xTaskNotifyFromISR(task, ~PIN_TRIG_A12P, eSetValueWithOverwrite, &xHigherPriorityTaskWoken);
|
||||
digitalWrite(PIN_TRIG_A12P, LOW);
|
||||
params->coil12p_high = false;
|
||||
}
|
||||
|
||||
if (params->state_time == (params->spark_delay_us + params->spark_pulse_us))
|
||||
{
|
||||
//xTaskNotifyFromISR(task, ~SPARK_A12, eSetValueWithOverwrite, &xHigherPriorityTaskWoken);
|
||||
digitalWrite(SPARK_A12, LOW);
|
||||
}
|
||||
|
||||
if (state_time >= 5*TIME_CONST) {
|
||||
xTaskNotifyFromISR(task, ~PIN_TRIG_A12P, eSetValueWithOverwrite, &xHigherPriorityTaskWoken);
|
||||
digitalWrite(PIN_TRIG_A12P, LOW);
|
||||
}
|
||||
|
||||
if (state_time >= 10*TIME_CONST) {
|
||||
state = S_12N;
|
||||
state_time = 0;
|
||||
if (params->state_time >= params->pause_short_us)
|
||||
{
|
||||
params->state = S_12N;
|
||||
params->state_time = 0;
|
||||
}
|
||||
break;
|
||||
|
||||
case S_12N:
|
||||
xTaskNotifyFromISR(task, PIN_TRIG_A12N, eSetValueWithOverwrite, &xHigherPriorityTaskWoken);
|
||||
digitalWrite(PIN_TRIG_A12N, HIGH);
|
||||
|
||||
if (state_time >= 5*TIME_CONST) {
|
||||
xTaskNotifyFromISR(task, ~PIN_TRIG_A12N, eSetValueWithOverwrite, &xHigherPriorityTaskWoken);
|
||||
case S_12N:
|
||||
if (params->state_time == params->clock_period_us && !params->coil12n_high)
|
||||
{
|
||||
//xTaskNotifyFromISR(task, PIN_TRIG_A12N, eSetValueWithOverwrite, &xHigherPriorityTaskWoken);
|
||||
digitalWrite(PIN_TRIG_A12N, HIGH);
|
||||
params->coil12n_high = true;
|
||||
}
|
||||
|
||||
if (params->state_time >= params->coil_pulse_us && params->coil12n_high)
|
||||
{
|
||||
//xTaskNotifyFromISR(task, ~PIN_TRIG_A12N, eSetValueWithOverwrite, &xHigherPriorityTaskWoken);
|
||||
digitalWrite(PIN_TRIG_A12N, LOW);
|
||||
state = S_WAIT_10MS;
|
||||
state_time = 0;
|
||||
params->coil12n_high = false;
|
||||
params->state = S_WAIT_10MS;
|
||||
params->state_time = 0;
|
||||
}
|
||||
break;
|
||||
|
||||
case S_WAIT_10MS:
|
||||
if (state_time >= 10*TIME_CONST) {
|
||||
state = S_34P;
|
||||
state_time = 0;
|
||||
if (!wait_sent)
|
||||
{
|
||||
//xTaskNotifyFromISR(task, S_WAIT_10MS, eSetValueWithOverwrite, &xHigherPriorityTaskWoken);
|
||||
wait_sent = true;
|
||||
}
|
||||
if (params->state_time >= params->pause_long_us)
|
||||
{
|
||||
params->state = S_34P;
|
||||
params->state_time = 0;
|
||||
}
|
||||
break;
|
||||
|
||||
case S_34P:
|
||||
xTaskNotifyFromISR(task, PIN_TRIG_A34P, eSetValueWithOverwrite, &xHigherPriorityTaskWoken);
|
||||
digitalWrite(PIN_TRIG_A34P, HIGH);
|
||||
if (params->state_time == params->clock_period_us && !params->coil34p_high)
|
||||
{
|
||||
//xTaskNotifyFromISR(task, PIN_TRIG_A34P, eSetValueWithOverwrite, &xHigherPriorityTaskWoken);
|
||||
digitalWrite(PIN_TRIG_A34P, HIGH);
|
||||
params->coil34p_high;
|
||||
wait_sent = false;
|
||||
}
|
||||
|
||||
if (state_time == 2*TIME_CONST){
|
||||
xTaskNotifyFromISR(task, SPARK_A34, eSetValueWithOverwrite, &xHigherPriorityTaskWoken);
|
||||
if (params->state_time == params->spark_delay_us)
|
||||
{
|
||||
//xTaskNotifyFromISR(task, SPARK_A34, eSetValueWithOverwrite, &xHigherPriorityTaskWoken);
|
||||
digitalWrite(SPARK_A34, HIGH);
|
||||
}
|
||||
|
||||
if (state_time == 7*TIME_CONST) {
|
||||
xTaskNotifyFromISR(task, ~SPARK_A34, eSetValueWithOverwrite, &xHigherPriorityTaskWoken);
|
||||
|
||||
if (params->state_time >= params->coil_pulse_us && params->coil34p_high)
|
||||
{
|
||||
//xTaskNotifyFromISR(task, ~PIN_TRIG_A34P, eSetValueWithOverwrite, &xHigherPriorityTaskWoken);
|
||||
digitalWrite(PIN_TRIG_A34P, LOW);
|
||||
params->coil34p_high = false;
|
||||
}
|
||||
|
||||
if (params->state_time == params->spark_delay_us + params->spark_pulse_us)
|
||||
{
|
||||
//xTaskNotifyFromISR(task, ~SPARK_A34, eSetValueWithOverwrite, &xHigherPriorityTaskWoken);
|
||||
digitalWrite(SPARK_A34, LOW);
|
||||
}
|
||||
|
||||
if (state_time >= 5*TIME_CONST) {
|
||||
xTaskNotifyFromISR(task, ~PIN_TRIG_A34P, eSetValueWithOverwrite, &xHigherPriorityTaskWoken);
|
||||
digitalWrite(PIN_TRIG_A34P, LOW);
|
||||
}
|
||||
|
||||
if (state_time >= 10*TIME_CONST) {
|
||||
state = S_34N;
|
||||
state_time = 0;
|
||||
if (params->state_time >= params->pause_short_us)
|
||||
{
|
||||
params->state = S_34N;
|
||||
params->state_time = 0;
|
||||
}
|
||||
break;
|
||||
|
||||
case S_34N:
|
||||
xTaskNotifyFromISR(task, PIN_TRIG_A34N, eSetValueWithOverwrite, &xHigherPriorityTaskWoken);
|
||||
digitalWrite(PIN_TRIG_A34N, HIGH);
|
||||
if (params->state_time == params->clock_period_us && !params->coil34n_high)
|
||||
{
|
||||
//xTaskNotifyFromISR(task, PIN_TRIG_A34N, eSetValueWithOverwrite, &xHigherPriorityTaskWoken);
|
||||
digitalWrite(PIN_TRIG_A34N, HIGH);
|
||||
params->coil34n_high = true;
|
||||
}
|
||||
|
||||
if (state_time >= 5*TIME_CONST) {
|
||||
xTaskNotifyFromISR(task, ~PIN_TRIG_A34N, eSetValueWithOverwrite, &xHigherPriorityTaskWoken);
|
||||
if (params->state_time >= params->coil_pulse_us && params->coil34n_high)
|
||||
{
|
||||
//xTaskNotifyFromISR(task, ~PIN_TRIG_A34N, eSetValueWithOverwrite, &xHigherPriorityTaskWoken);
|
||||
digitalWrite(PIN_TRIG_A34N, LOW);
|
||||
state = S_WAIT_10MS_END;
|
||||
state_time = 0;
|
||||
params->coil34n_high = false;
|
||||
params->state = S_WAIT_10MS_END;
|
||||
params->state_time = 0;
|
||||
}
|
||||
break;
|
||||
|
||||
case S_WAIT_10MS_END:
|
||||
if (state_time >= 10*TIME_CONST) {
|
||||
state = S_12P;
|
||||
state_time = 0;
|
||||
if (!wait_sent)
|
||||
{
|
||||
//xTaskNotifyFromISR(task, S_WAIT_10MS_END, eSetValueWithOverwrite, &xHigherPriorityTaskWoken);
|
||||
wait_sent = true;
|
||||
}
|
||||
if (params->state_time >= params->pause_long_us)
|
||||
{
|
||||
params->state = S_12P;
|
||||
params->state_time = 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
digitalWrite(PIN_TRIG_B12P, LOW);
|
||||
|
||||
if (xHigherPriorityTaskWoken)
|
||||
portYIELD_FROM_ISR();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user