i have this Arduino working code this part of lt what i need is how to use this code with esp8266 note that on arduino i can use also digital pins not only A0 A1 and A2
[code]
#include <TimerOne.h>
volatile int CYCLE_TIME =1562;
volatile int FREQUENCY = 640;
volatile int TX_PULSE = 100;
volatile int PULSE_1_DELAY = 20;
volatile int PULSE_1 = 45;
volatile int PULSE_2_DELAY = 150;
volatile int PULSE_2 = 45;
volatile unsigned long timer = 0;
void setup()
{
pinMode (A0, OUTPUT);
pinMode (A1, OUTPUT);
pinMode (A2, OUTPUT);
digitalWrite (A0, LOW);
digitalWrite (A1, LOW);
digitalWrite (A2, LOW);
Serial.begin(9600);
Timer1.initialize(CYCLE_TIME);
Timer1.attachInterrupt(do_isr);
}
void loop()
{
void do_isr()
{
PINC = 0x01;
for(int i = 0; i < TX_PULSE; i++)
{
__asm__("nop\n\tnop\n\tnop\n\tnop\n\tnop\n\t");
__asm__("nop\n\tnop\n\tnop\n\tnop\n\tnop\n\t");
__asm__("nop\n\tnop\n\t");
}
PINC = 0x01;
for(int i = 0; i < PULSE_1_DELAY; i++)
{
__asm__("nop\n\tnop\n\tnop\n\tnop\n\tnop\n\t");
__asm__("nop\n\tnop\n\tnop\n\tnop\n\tnop\n\t");
__asm__("nop\n\tnop\n\t");
}
PINC = 0x02;
for(int i = 0; i < PULSE_1; i++)
{
__asm__("nop\n\tnop\n\tnop\n\tnop\n\tnop\n\t");
__asm__("nop\n\tnop\n\tnop\n\tnop\n\tnop\n\t");
__asm__("nop\n\tnop\n\t");
}
PINC = 0x02;
for(int i = 0; i < PULSE_2_DELAY; i++)
{
__asm__("nop\n\tnop\n\tnop\n\tnop\n\tnop\n\t");
__asm__("nop\n\tnop\n\tnop\n\tnop\n\tnop\n\t");
__asm__("nop\n\tnop\n\t");
}
PINC = 0x04;
for(int i = 0; i < PULSE_2; i++)
{
__asm__("nop\n\tnop\n\tnop\n\tnop\n\tnop\n\t");
__asm__("nop\n\tnop\n\tnop\n\tnop\n\tnop\n\t");
__asm__("nop\n\tnop\n\t");
}
PINC = 0x04;
}
[/code]
Perhaps you should heed that advice and try TickTwo instead.
In addition, your sketch uses the special feature of the AVR processor that toggles a bit in the PORT register when a 1 is written to the corresponding bit in the PIN register. You will need an ESP8266 way to quickly toggle an output pin.
You can almost certainly change output pins in the same pattern but the timing is likely to be (very) different. I have no idea if the ESP8266 can digitalRead() an OUTPUT pin. If it can then: PINC = 0x01; // Toggle A0 output
could be changed to: digitalWrite(A0, !digitalRead(A0));
(Where 'A0' resolves to an output pin number.)
If it can't, you'll have to keep a state variable for each output pin:
Trying to port assembler-code from a microcontroller of type Atmel328 (Arduino) to a microcontroller type Xtensa LX106 (ESP8266) is like trying to fasten such a screw
with this tool
Assembler-code is below the level of C++-coding.
Each microcontroller has its own "core" which is used to translate "high-level" commands like digitalWrite() if() etc. into that kind of assembler-code that suits to that exact type of microcontroller.
So a direct port of assembler-code is simply impossible.
You have just ask for a detail. What is the final purpose of your project?
Creating nanosecond short pulses is not a self-purpose.
If you describe what you want to do in the end the final purpose
well suited suggestions can be made.
Creating nanosecond short pulses is not a self-purpose. Yes sure
Using Arduino gives microsecond delay
It fits what I did and what i am using it for it is timing clock for pulsed metal detector. i am Doing these things for fun and entertainment. The rest of the code is to control variables such as frequency, delay, etc.
A0 Generates a signal with a variable frequency in the kilohertz range and a variable pulse width from one hundred and fifty microseconds to four hundred microseconds
the code in the first post working fine for the metal detector
what i am thinking now is to use same manner of the arduino uno sketch with ESP8266 to get sub nanosecond delay i want to play with rangefinders or time domain reflectometry motion sensor etc
how to make this using ESP8266 with arduino IDE ؟
I am not restricted to the code above it is just an idea how to make a nanosecond delay using ESP8266 as arduino did in microsecond