-->
Page 1 of 2

duration NOP instruction

PostPosted: Fri Dec 19, 2014 9:28 am
by nicoverduin
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:

Re: duration NOP instruction

PostPosted: Fri Dec 19, 2014 11:57 am
by joostn
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.

Re: duration NOP instruction

PostPosted: Fri Dec 19, 2014 1:46 pm
by nicoverduin
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);
}

Re: duration NOP instruction

PostPosted: Sun Dec 21, 2014 3:36 pm
by RogerClark
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.