Forum: Mikrocontroller und Digitale Elektronik ESP32 General Purpose Timer


von Welle 🧐 S. (w3llschmidt)


Angehängte Dateien:

Lesenswert?

Hallo Leute,

ich bekomme es nicht hin einen einfachen 10s Timer mit autoreload zu
erstellen ...
1
#include <stdio.h>
2
#include "freertos/FreeRTOS.h"
3
#include "freertos/task.h"
4
#include "freertos/queue.h"
5
#include "driver/timer.h"
6
7
#define TIMER_DIVIDER         (16)
8
#define TIMER_SCALE           (TIMER_BASE_CLK / TIMER_DIVIDER)
9
10
uint64_t counter_value;
11
12
static void app_timer_init(int group, int timer, bool auto_reload, int timer_interval_sec)
13
{
14
15
    timer_config_t config = {
16
        .divider = TIMER_DIVIDER,
17
        .counter_dir = TIMER_COUNT_UP,
18
        .counter_en = TIMER_PAUSE,
19
        .alarm_en = TIMER_ALARM_EN,
20
        .auto_reload = auto_reload,
21
    };
22
    timer_init(group, timer, &config);
23
24
    timer_set_alarm_value(group, timer, timer_interval_sec * TIMER_SCALE);
25
  
26
  timer_start(group, timer);
27
28
}
29
30
31
void show_timer_task() 
32
{
33
34
    while(1) {
35
36
    timer_get_counter_value(TIMER_GROUP_0, TIMER_0, &counter_value);
37
    printf("%.0f\n", (float) counter_value / TIMER_SCALE);
38
39
    vTaskDelay(1000 / portTICK_PERIOD_MS);
40
    }
41
}
42
43
44
void app_main(void) 
45
{
46
47
  app_timer_init(TIMER_GROUP_0, TIMER_0, true, 10);
48
49
    xTaskCreatePinnedToCore( show_timer_task, "show_timer_task", 2048, NULL, 1, NULL, 1 );

Der Timer laeuft beim zweiten mal ohne Reload auf 0 ???

: Bearbeitet durch User
Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.