-
My CNC Machine
06/30/2017 at 03:22 • 0 commentsJust a picture of my CNC machine
-
ESP8266 Timer0 and ISR
10/12/2016 at 13:26 • 2 commentsA timer and interrupt system for the ESP8266
The current method of managing timing signals for Not-GRBL is by a "blink without delay" style of programming.
It is somewhat restrictive but it works.
This style of programming is also called "polling" and is basically the same a the "Ticker" library.
What is really needed is access to a hardware timer and an Interrupt Service Vector.
The ESP8266 provided a simple non-resetable up counter (the so called software timer) called timer0.
Basically this timer counts clock cycles (i.e. at 80 MHz).
Here is a bit of code the write my own "servo sweep":
#define servoPin D4 volatile int servoPulse=0; volatile int servoAngle=90; volatile unsigned long next; void inline servoISR(void){ if (servoPulse==0) { next=next+40000+889*servoAngle; } else { next=next+1560000-889*servoAngle; } timer0_write(next); servoPulse=1-servoPulse; digitalWrite(servoPin,servoPulse); } void setup() { // Servo initialisation (uses D4) pinMode(D4,OUTPUT); noInterrupts(); timer0_isr_init(); timer0_attachInterrupt(servoISR); next=ESP.getCycleCount()+1000; timer0_write(next); interrupts(); // Serial.begin(9600); // Serial.println(); } void loop() { const int minAngle=16; const int maxAngle=176; const int midAngle=96; static int servoDir=1; delay(50); // Next position if (servoAngle>maxAngle) servoAngle=maxAngle; if (servoAngle<minAngle) servoAngle=minAngle; if (servoAngle==maxAngle) servoDir=-servoDir; if (servoAngle==minAngle) servoDir=-servoDir; servoAngle+=servoDir; // Serial.println(servoAngle); }
Here is the critical bit of code:
noInterrupts(); timer0_isr_init(); timer0_attachInterrupt(servoISR); next=ESP.getCycleCount()+1000; timer0_write(next); interrupts();
What does it do?
- Initialises the timer
- Attach the interrupt service routine (ISR)
- Gets the current clock count and add 1000 clock cycle to it
- Tell the timer to call the ISR after 1000 clock cycles
It takes about 180 clock cycles to call the ISR.
Limitations
Other processes use the same timer and it has been reported that a 2 ms tick will crash the ESP6288 if you are using WiFi.
Other timers
There is also a timer1 (that needs investigation).
AlanX
-
The Ticker Library
09/02/2016 at 09:00 • 0 commentsThe Ticker Library
The code in "Not Grbl" does not use any hardware timers because I want to eventually migrate to the EPS2688 and the hardware on this CPU is not well documented (unlike the AVRs). The code use "Blink without delay()" type code. On an Nano the code loops through at a rate of about 8 kHz. Plenty fast for a gCode interpreter/stepper controller.
As the Ticker Library works on the EPS2688 series of boards (I have a WeMos D1R1 and an EPS-12E), I thought I would have a look.
I tested the code on my Dalek motor/sensor board. It worked but not as expected. Basically the Library uses the millis() routine to manage/schedule the attach class. It is not interrupt based. So it basically it is "Blink without delay()" type code. So don't add a long delay() in anywhere if you use it. It is very tidy and nice to use but as I use micros() rather than millis() in "Not Grbl". It is therefore not a suitable library for use at present.
AlanX
-
Project Complete?
08/18/2016 at 07:50 • 0 commentsProject Complete
I have not looked at this project for a while and it works fine anytime I use it (mainly for my laser engraver).
There may be some future upgrades but that can be done when required.
The only thing I have noticed is that with the laser there is a distinct spot with fast movements that is very likely associated with the speed ramp down and ramp up between each movement command.
This ramp down and ramp up limits movement changes to an acceleration of less than 1 g and gives the steppers a distinctive low pitch grumble.
There are other ways of dealing with this but it is a simple system, works well and not worth upgrading.
I added a couple of useful files if your looking for motion control code:
- ArcDouble (not used for Not Grbl) but draws two arcs .
- 3DStepper does the 3d stepper motion magic.
AlanX