SHARE
TWEET

Untitled

a guest Mar 25th, 2019 53 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include "freertos/FreeRTOS.h"
  3. #include "freertos/task.h"
  4. #include "driver/gpio.h"
  5. #include "wrpTimer.h"
  6. #include "driver/periph_ctrl.h"
  7.  
  8. void timerInit(timer_group_t tGroup, timer_idx_t tVal){
  9.     timer_config_t config;
  10.     config.divider = TIMER_DIVIDER;
  11.     config.counter_dir = TIMER_COUNT_UP;
  12.     config.counter_en = TIMER_PAUSE;
  13.     config.alarm_en = TIMER_ALARM_EN;
  14.     config.intr_type = TIMER_INTR_LEVEL;
  15.     config.auto_reload = 0; //don't autoreload
  16.     timer_init(tGroup, tVal, &config);
  17.  
  18.     timer_set_counter_value(TIMER_GROUP_0, tVal, 0x00000000ULL); // starts timer from 0
  19.     timer_start(tGroup, tVal); //starts the timer initially
  20. }
  21.  
  22. void tTriggerInUs(uint32_t micros, timer_group_t tGroup, timer_idx_t tVal){
  23.     uint64_t counter_old = 0;
  24.     timer_get_counter_value(TIMER_GROUP_0,TIMER_0,counter_old);
  25.     uint64_t counter_add = (micros * TIMER_SCALE) / 1000;
  26.     timer_set_alarm_value(tGroup, tVal, counter_old+counter_add);
  27. }
  28.  
  29. void tTriggerInMs(uint16_t millis, timer_group_t tGroup, timer_idx_t tVal){
  30.     uint64_t counter_old = 0;
  31.     timer_get_counter_value(TIMER_GROUP_0,TIMER_0,counter_old);
  32.     uint64_t counter_add = millis * TIMER_SCALE;
  33.     timer_set_alarm_value(tGroup, tVal, counter_old+counter_add);
  34. }
  35.  
  36. void tEnableAlarm(timer_group_t tGroup, timer_idx_t tVal){
  37.     timer_set_alarm(tGroup, tVal, TIMER_ALARM_EN);
  38. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top