-->
Page 1 of 1

os_timer_arm_us work same as os_timer_arm?!!

PostPosted: Sat Oct 14, 2017 4:59 am
by soroosh
Hi
I use os_timer_arm_us to generate 4uS square wave with 50% duty cycle but that makes 4mS square wave!!!
What is my mistake?
Thank you
Code: Select all#define out_pin 5
volatile unsigned long timeSpent=1;
volatile int toggle;
unsigned long prevMillis=0;
unsigned long current_time=0;

extern "C" {
#define USE_US_TIMER
#include "user_interface.h"
#include "osapi.h"
#define os_timer_arm_us(a, b, c) ets_timer_arm_new(a, b, c, 0)
}

os_timer_t t0;


void myIsrTimer(void*z)
{
  current_time = micros();
  timeSpent = current_time - prevMillis;
  prevMillis =  current_time; 
  //toggle = (toggle == 1) ? 0 : 1;
  //digitalWrite(out_pin,toggle); 
}

void setup() {
  pinMode(out_pin, OUTPUT); 
  os_timer_setfn(&t0, myIsrTimer, NULL);
  os_timer_arm(&t0, 4, true);
  // Initialise Serial connection
  Serial.begin(115200);
 }

void loop() {
  Serial.print(timeSpent);Serial.print(" ");
}

Re: os_timer_arm_us work same as os_timer_arm?!!

PostPosted: Tue Apr 17, 2018 6:55 am
by Henning
Hello,
I have the same problem ... soroosh, did you fixed this problem meanwhile ?

Example:
Code: Select allos_timer_arm_us( &myTimer, 100, 1 );

This results in a 100ms Interval, not 100us.

Did anybody already used an us-timer successfully on the esp8266 ?

friendly regards
Henning

Re: os_timer_arm_us work same as os_timer_arm?!!

PostPosted: Tue Apr 17, 2018 8:49 pm
by tele_player
I found this somewhere:


void os_timer_arm_us(os_timer_t *ptimer,
uint32_t microseconds,
bool repeat_flag)
os_timer_t *ptimer: timer structure.
uint32_t microseconds: timing; unit: microsecond, the minimum value is 0x64, the maximum value allowed to input is 0xFFFFFFF.
bool repeat_flag: whether the timer will be invoked repeatedly or not.


Apparently, this comes from Espressif SDK documentation.

So, I would try much larger values, just to see if it works, such as 1000, 10000.

Re: os_timer_arm_us work same as os_timer_arm?!!

PostPosted: Mon Feb 04, 2019 7:53 am
by RuiViana
Hi, Soroosh and Henning,
I had the same problem, and I solved
calling the function "system_timer_reinit ();" at the
start of my "user_init".
Like this:

extern "C" {
#define USE_US_TIMER
#include "user_interface.h"
#include "osapi.h"
#define os_timer_arm_us (a, b, c) ets_timer_arm_new (a, b, c, 0)
}
os_timer_t mTimer;
// ------------------------------------------------ -------------------
void usrInit (void) {
     system_timer_reinit ();
     os_timer_setfn (& mTimer, tCallback, NULL);
     os_timer_arm_us (& mTimer, 1000, true);
}

RV