Use this forum to chat about hardware specific topics for the ESP8266 (peripherals, memory, clocks, JTAG, programming)

User avatar
By nicoverduin
#5167 Hi all
I am trying to figure out how long does it take the ESP8266ex to process a NOP instruction. I need some strict timing pulses and it would either be using the interrupt timer or hard coded. I have been digging through some of the LX106 manuals... but I am lost :mrgreen:
User avatar
By joostn
#5185 In my tests
Code: Select all__asm__ __volatile__ ("nop");
takes 1/80000000 second, i.e. one clock pulse.

Now if you find out how to use interrupt timers please let me know.
User avatar
By nicoverduin
#5195 This is from a file (io.c) in esphttpd server project from Jeroen Domburg

Code: Select all**
 * @file io.c
 * Handles all the IO functions within this program
 * ----------------------------------------------------------------------------
 * "THE BEER-WARE LICENSE" (Revision 42):
 * Jeroen Domburg <jeroen@spritesmods.com> wrote this file. As long as you retain
 * this notice you can do whatever you want with this stuff. If we meet some day,
 * and you think this stuff is worth it, you can buy me a beer in return.
 * ----------------------------------------------------------------------------
 */
//
// includes
//
#include "espmissingincludes.h"
#include "c_types.h"
#include "user_interface.h"
#include "espconn.h"
#include "mem.h"
#include "osapi.h"
#include "gpio.h"
//
// pin definitions
//
#define LEDGPIO 2
#define BTNGPIO 0

static ETSTimer resetBtntimer;        // counts the interrupts
/**
 * @name resetBtnTimerCb(void *arg)
 * @param arg parameter is ignored here
 * timer function called based on the timer function
 */
static void ICACHE_FLASH_ATTR resetBtnTimerCb(void *arg) {

   static int resetCnt=0;
        //
        // check if the button is pressed
        //
   if (!GPIO_INPUT_GET(BTNGPIO)) {
      //
      // increment the counter
      //
      resetCnt++;
   } else {
      //
      // check if more than 3 seconds are pressed
      //
      if (resetCnt>=6) {                // 3 sec pressed as the timer is set for once every 500mS
         //
         // disconnect from the LAN
         //
         wifi_station_disconnect();
         //
         // reset to AP + STA mode
         //
         wifi_set_opmode(0x3); //reset to AP+STA mode
         os_printf("Reset to AP mode. Restarting system...\n");
         //
         // restart system
         //
         system_restart();
      }
      //
      // reset the counter
      //
      resetCnt=0;
   }
}
/**
 * @name ioInit()
 * Initialize IO pins and timers
 */
void ioInit() {
   //
   // select pins GPIO0 and GPIO2
   //
   PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO2_U, FUNC_GPIO2);
   PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO0_U, FUNC_GPIO0);
   //
   // Set the button as Input and LED as output
   //
   gpio_output_set(0, 0, (1<<LEDGPIO), (1<<BTNGPIO));
   //
   // turn off timer
   //
   os_timer_disarm(&resetBtntimer);
   //
   // set the timer call back function
   //
   os_timer_setfn(&resetBtntimer, resetBtnTimerCb, NULL);
   //
   // turn timer on to trigger each .5 second
   //
   os_timer_arm(&resetBtntimer, 500, 1);
}
User avatar
By RogerClark
#5347 Isn't there a os_delay_us() function that does this.

But for very accurate timing, you are better off declaring a using a for loop, and declare the loop variable as volatile.

That way the compiler is forced to generate the code even if the for loop is empty.