The field service manual is quite helpful, but the pin numbers of the connectors are not labeled and there are no part number.
Between the manual and some measurements with my meter, I think I have it figured out.
Power Supply.
I do not have the original external (wall wart) power supply. You can tell it is AC from the schematic. I did some research and found out it is 9VAC. That goes through (2) 5V volt linear regulators (with a huge heatsink). One powers the stepper motors and all the logic. The other powers the pen up/down solenoid.
Basically, I should be able to power everything with a robust 5VDC power supply. I’ll probably use this style.
The function switches are normally open, momentary switches that close to ground.
Here is the pinout of that cable.
Pin #
Description
Wire color
1
Grn
Black
2
Pen Change Sw
Blue
3
Paper Feed Sw
Pink
4
pen Change Sw
Yellow
5
Power (in)
Red
6
Power (out)
Red
Pen Solenoid
Then pen moves to and away from the paper using a solenoid. The schematic is amazingly complex here, but basically the voltage flows one way through it for pen up and the for pen down. It is a 5V coil with a resistance of 5.2 Ohm.
Stepper motors
There are (2) stepper motors. One is for the paper feed and the other moves the pen carriage. These motors are 5 wire unipolar motors. These are typically used by connecting the common to voltage+ and the other wires to transistors. If sequenced on one at a time, you get 4 independent coils.
The coil resistance of the paper feed stepper coils is 50 Ohm and the carriage is 60 Ohm.
Pen Change, Homing switch
There is a reed switch activated by a magnet in the pen carriage.
Printer Mechanism Cable
There is a 13 pin cable that connects everything in the plotter mechanism to the controller PCB. This uses a Molex connector p/n 511911300. The mate on the PCB is Molex p/n 22041131. The pinout is here.
I recently decided to update the Polar Coaster project. The primary reason was to update the controller to use Grbl_ESP32 firmware. I also thought I could make it smaller, lighter and remove a little cost.
Controller
The old controller was not custom made and just sort of tacked onto the back. This increased the size and didn’t look very good. It had a Bluetooth module, but you still had to stream the gcode. You could use an Android app, but that was still a little awkward.
Firmware
The controller runs Grbl_ESP32. This was recently updated to include pen machine features. This allows precise control and calibration of the pen servo. You can control the speed, timing and endpoints of the servo travel.
WebUI
The controller has a web server that serves a web app. This allows complete control of the machine. Web browser based control is ideal, because it is compatible with anything that can use a browser. We hope to add additional web apps for generating gcode from images and SVGs.
SD Card
This is a great feature. If you have files on the SD card, they can easily be plotted. The WebUI lets you upload files and then click play.
Stepper motors
Both versions use NEMA 14 motors. The original version used 34mm deep motors. I used these because I had some. They are overkill, because there is very little load on the motors. I bought some 20mm deep motors for the new version. These are even a little overkill. I am only running about 0.3A of current into each one. There are not too many options for standard stepper motors that are smaller and lower cost than these.
Gear Driven Rotational Axis
I decided to change from a belt driven rational axis to a gear driven one. Loop belts are a pain, because you have to order them from expensive places like SDP-SI and if you want to tweak anything, you might need to order a different size. I decided to use helix gears this time. These are 15° gears with a modulus of 1. They print and work great with my printer, even on a coarse layer height. The motor is mounted on slots and it is easy to get virtually no backlash. The helix keeps them quiet.
Rotational Platter
The platter rotates around a central bearing. This pulls (3) smaller bearings, that act like wheels, into contact with the PCB. This causes the platter to stay very flat, without wobble. I created a copper ring, plated with solder on the PCB to make it extra smooth and wear resistant. It also looks really cool and shiny on the PCB!
Buttons
Since there was a little room left on he board, I added three buttons. I have not added anything to the firmware yet. I think one will definitely be a homing button. I am not sure what to use the others for. I thought it might be handy to have a repeat button to repeat the last plot without having to fire up the phone app.
Battery Power
I made a battery case in the base of the machine to hold an RC style LiPo battery. I am using a 3 cell (11.1V) 2200 mah battery. The idle current on the machine with the WiFi running is about 80ma. When plotting it peaks at about 800ma. I think I should get about 2 hours of continuous plotting.
Future
Put kinematics into the firmware. currently files need to be pre-processed with the python script.
If you want to be notified of future blog posts, please subscribe.
I have done several pen and laser machines lately, so I decided to create a custom PCB for Grbl_ESP32 for these types of machines. This is a small (70mm x 60mm) PCB with all the features a pen plotter or laser cutter/engraver would need.
These typically use stepper motors for the X and Y axes. On pen plotters, the Z axis is controlled by a servo or solenoid. On lasers you need an accurate PWM for laser power control.
Here are the features of the PCB assembly
(2) Stepper Motor Driver Sockets for standard stepper driver modules.
(1) Hobby Servo Connector.
(1) High Current (10A max) Output Control. This can be used for a solenoid, fans, etc.
(2) limit/Home Switch Connectors.
Laser Power PWM connector
Removable Micro SD card. Upload files via Wifi to reliably run off-line.
5V 3A Step Down Power Supply
Standard DC Barrel Connector for power input. (9-28 VDC)
Power Output Connection for laser module.
Grbl_ESP32 Advanced Features
32-Bit dual core processor
Fast 120kHz step rates
WiFi
Access point or station modes
Complete web user interface
Telnet
Bluetooth Serial
Compatible with phone apps
Compatible with most serial port gcode senders
16 bit laser power control.
Core XY kinematics supported for T style machines.
RTOS (real time operating system) allows the use of custom tasks.
Precise servo control accurately mapped to Z motion, plus interactive calibration.
Precise control of solenoids via adjustable pull and hold strengths using PWM. This allows a strong pull, yet a cool hold temperature.
Instant On/Off – Unlike a Raspberry Pi, there is no long boot time or formal shutdown required. It is typically ready to go in a few seconds.
How to control it
There are several ways to connect to the controller, but to run jobs, you basically either stream the gcode or run it from a file on the SD card. The SD card is a great feature because it is free from connectivity interruptions and you don’t need to stay connected to your machine while it is running the job. You can quickly upload files via WiFi or remove it and plug it into your computer.
Serial port
This controller is compatible with virtually all of the serial port gcode senders for Grbl. The default baud rate is 115200.
Bluetooth Serial
This is a great way to use your phone to control a machine. When you connect via bluetooth, your phone or computer will create a virtual serial port. This means you can then use existing serial port based gcode senders.
Wifi – WebUI
The controller has a web server. The controller can create its own WiFi access point or connect to an existing WiFi network. You connect to the controller with a web browser and it serves a full featured machine controller to browser.
Controlling the Pen Up/Down Servo
The servo is controlled using a separate RTOS task on the controller. Grbl thinks it is running a normal stepper motor on the Z axis. Each time the servo task runs, it looks at the current position of the Z. It then computes and sets a position for the servo. You map the servo’s range to a Z range. For example the range could be set for 0-5mm. Any values of Z above or below this range would would be limited by the range, so any Z value above 5mm in this example would not move the servo past where it was at 5mm.
You can calibrate the end points of the servo to fine tune it. We use the Z axis resolution and max travel settings to do this. $102=100 (100%) would be no change to the first end point. %102=90 or $120=110 would be 10% changes in either direction. $132 works the same way for the other end point. Make sure you do not adjust the servo so it hits the physical end point of its travel. You will feel the servo continuously vibrating as it pushes against the end point. This is very hard on a servo and will overheat and damage it.
The servo updates its position 20 times per second. Therefore it will do a good job of respecting the acceleration and speed settings in the gcode.
The feature also uses the $1 (Step idle delay) setting. It the steppers motors disable, so will the servo and can be moved manually.
Additional parts you need
The controller uses plug in modules for the the ESP32 controller and the stepper motor drivers.
ESP32 Controller
The ESP32 controller needs to be a ESP32 Dev Module. It should have 2 rows of 19 pins. The rows should be spaced 0.9 inch (22.86mm) apart. Be careful: Some similar controllers have a wider pitch.
Stepper Motor Drivers
The drivers are the standard StepStick (Pololu) style footprint. The (3) microstepping selection pins (MS1, MS2, MS3) are all connected to logic high. This typically results in the highest resolution (1/16 or 1/32). The Grbl_ESP32 step rates are high enough to make that not an issue. I typically use TI DRV 8825 or Allego A4988 modules, but others can be used as long as the pins are compatible. The PCB silkscreen has the corner pins labeled. Use them to insure you correctly install your driver modules.
Source Files (coming soon)
A completely assembled PCB is available on Tindie. The profits from Tindie help me to continue to develop the hardware and firmware for projects like this. If you want to roll your own, the source files are linked below.
I and Jason Huggins (@hugs), of Tapster Robotics, will be giving a conference at the 2018 Hackaday SuperConference. The conference will be “Getting Started in Small Scale CNC and Robotics (Build a CNC Badge)”. By the end of the workshop you will have built, programmed and learned to use the DrawBot Badge.
The badge is way more than that though. The badge PCB is a very capable general purpose CNC/Robotics controller. We considered every small scale CNC machine we could think of and made sure this badge could control it. Here is what it can control.
(3) Stepper Motors
(3) Hobby Servos
(3) Homing/Limit switches
(1) Variable Speed Spindle PWM signal
(1) Laser Module (Power control and Safety interlock)
(4) Control switch inputs
(1) Probe switch control
(1) Coolant Control
(1) High current (3 Amp) output for relays or solenoids (includes flyback diode)
(1) i2C interface (for displays or Sh**ty Add-Ons)
(1) SD Card socket to store and run files
You can’t use every feature at once, like the Laser PWM and Spindle PWM are the same signal, but they are broken out logically to multiple, machine specific, connectors.
It is all powered by an ESP32 running Grbl_ESP32, which provides serial, Bluetooth and WebUI interfaces.
The first half of the conference will cover tips and tricks for getting started with making and controlling small machines. We will also learn and use some basic gcode to control some motors and other items. It is a just a basic intro to get you started and discover some resources. During the second half we will build the DrawBot badge.
If you are interested, sign up for the conference and be sure to get into the workshop when that is posted. The workshop will be limited to about 20 people, but I will bring extra badges for sale and will be happy to help build and hack them all weekend. I will also bring extra motors, servos, switches, etc for hacking up simple machines.
Open Source
Within the next couple weeks, all of the documentation will be released. Badge kits will also be for sale on Tindie after the conference.
I showed off an early version of my DrawBot Badge at the Hardware Happy Hour last night. Some tweeted pictures generated a lot of questions, so I thought I would write a quick post about it.
I have been following the #badgelife thing for a few years and felt that the mechanical and CNC world needed to be represented. The goal was to create something small, safe, fun and something anyone could learn to use. A drawing machine seemed the perfect fit.
Drawing Surface
I decided to use 3″ square Post-It notes. The main feature is that they are self stick, so I don’t need any clamps or tape. It is also cool that you can stick them to things when the drawing is done. They are cheap and easy to find. I like the kind that have the majority of the back (full stick) covered in adhesive. This means you can use a small stack of them and peel them off as they are done.
Drawing Mechanism
I tried to make the drawing mechanism as tiny as possible. The size is about 30mm x 70mm. It uses (3) of the smallest readily available class of hobby servos call micro servos. You can buy these from AliExpress for as low $1-$2 in low quantities. The choice of the arm configurations was primarily based on tightly packing the the motors, but I also wanted something new and interesting.
The pen lift is simply a cam on one of the motors. The entire mechanism rotates on two 3mm bearings. In my experience with drawing machines, gravity is the best way to engage the pen to the work. The mechanism needed to work hanging from a lanyard or sitting on a table.
Electronics
There is only one electronic item right now. It is an ESP32 dev module. There are also (3) connectors for the servos and (1) for voltage monitoring. The entire back of the badge is a PCB. I made the board full size to enclose the back and the pen lift cam need to push on something. I have big plans for the rest of the area though. The ESP32 provides the Bluetooth and Wifi needed for the remote control.
Firmware
It is running my ESP32 port of Grbl with a little hacking for the servos. The ESP32 uses an RTOS, so I just created a low priority, repeating task (20Hz). The task checks the position of a virtual CNC machine, does some kinematic math and updates the servos. The software supports streaming drawing data (gcode) via serial port, bluetooth, SD card or wifi. I am using the bluetooth option to send via my phone. I will publish the firmware soon.
Crazy Math (Kinematics)
The math is actually not too hard. You know the desired pen location, the axes of the servos and the lengths of the linkages. There are two ways to do the math. The first way is using the law of cosines and the Pythagorean theorem.
The second method uses intersecting circles. Each linkage can sweep a circle from a axis point and radius. Any two linkage’s circles will intersect at two points. It is easy to pick one of the points as more desirable. While it is less deterministic, due to the two points thing, it appears to run about 40% faster on the ESP32.
The Z is very simple. Any Z value less than 0 is pen down and everything else is pen up.
Drawing Quality
The quality is basically “Adorably Wiggly”. I am using the cheapest analog servos. That means I might get about 200 x 200 resolution at best at the servo hubs. If you mapped that grid to the paper it would be a warped grid with dense and sparse areas of the grid due to the non-linear nature of the mechanism. Digital servos with very low deadbands (~1us) it would probably do a lot better, but I am not sure that is worth it. It would only be a little less wiggly. They cost about 4x what analog servos do (still pretty cheap).
There is a calibration feature. Each servo is a little different and it is difficult to precisely mount the arms at the right angle. The calibration adjusts the zero angle and pwm/degree of rotation.
Next Steps
This project is part of a talk proposal for Hackaday SuperCon 2018. If that gets accepted, the badge will become a full featured CNC controller capable of running a router, laser cutters, high res plotter, etc, as well as the Drawbot badge. Only the DrawBot will be populated. The rest will be modular like this board.
I may also make a simple version that is only the draw bot. The BOM cost is currently about $10-$12 (without 3D printed parts)
Regardless of what happens all source files will be publish sometime in October.
Follow me on Twitter (@buildlog) or subscribe to this blog if you want to follow the project.
If you want to be notified of future blog posts, please subscribe.
Bluetooth Serial has now been added to the master branch of Grbl_ESP32. Bluetooth Serial means the Bluetooth connection looks like a serial port when you pair with the device. This is ideal because it allows all existing gcode senders that support serial ports to use Bluetooth.
This was added using the Bluetooth Serial library that is part of the espressif/arduino-esp32 development environment. This library is relatively new and has a few issues, but I was able to work around them.
Sending Characters: The reporting done by Grbl sends characters a character at a time. This means dozens of calls to the library are needed for each response. This caused characters to be dropped. The solution is to send a full string in a single call using .print(), rather than sending individual characters using .write(). Grbl was written using the character at a time method to highly optimize the reporting. The raw speed of the ESP32 does not require that optimization and the resulting code is much more readable.
No Password: The library does not support the use of a password for the pairing. This is a big drawback, and needs to be considered before you enable Bluetooth. Apparently this was due to an upstream component that has now been fixed. Hopefully it means the library will be updated soon.
Why and when to use it.
The cost, size and wireless features of the ESP32 are the primary reason I ported Grbl to the ESP32. I make a lot of tiny CNC machines. A laptop is likely to be many times the size of the CNC machine. I wanted to control the machines via a phone or small tablet. I have found the connection to be very reliable, even for jobs lasting more than an hour. The phone can even be in the “off” state in your pocket and it will still stream reliably. The battery drain is accelerated, but not significantly (like listening to audio via Bluetooth) You do need to stay within range of the machine, although Grbl Controller (Android) appears to be able to resume a job.
Using Bluetooth.
It is optional. You enable the feature at compile time. That allows you to save some code space (not really an issue now). Once the feature is enabled, you can still turn it on or off via a serial port command. All Bluetooth traffic is echo’d to the serial port. This allows you to monitor the communications. You can also use the Serial port at any time, but it is not a good idea to do that while running a job. Here are the steps to set it up.
Make sure #define ENABLE_BLUETOOTH is not commented out in config.h.
Use a serial port terminal to set the Bluetooth name using $I=NAME, where NAME is the Bluetooth name you want. I don’t know all the naming rules, so keep it short and simple. There is no capability to use a password yet. Grbl converts all input to capital letters, so lowercase will cannot be used.
Reboot the ESP32 to turn on Bluetooth with that name. Grbl will send Starting Bluetooth:ESP32BT as the first item when booting to let you know Bluetooth is on. ESP32BT is the Bluetooth name I used in this case. Grbl will now respond on either Bluetooth or Serial data. All Bluetooth sends are echo’d on the Serial port if you want to watch the data.
You can now pair a phone or PC with Grbl_ESP32.
Caution: Do not pair while running a job. The ESP32 will likely interrupt and/or watchdog issues while the stepper timer is running and the pairing process is running.
Next Steps
Other modes: A phone also makes an awesome display and control panel. Maybe the PC is the primary sender and the phone acts as a pendant.
SD card. SD card is next on the roadmap. This pairs well with bluetooth, because the phone could select and start an SD card job.
If you want to be notified of future blog posts, please subscribe.
I started working on my next backpack scale CNC project. My backpack scale projects are tiny CNC machines that I can easy carry in a backpack to tech meetups and events. This machine is going to be a wooden nickel laser engraver.
Wooden nickels are small wooden discs. You can buy blanks from various places, including Amazon. You can usually get 100 for less than $10. The goal is to create a machine that loads them from a feed tube, engraves them, then ejects them.
Mechatronics
The basic drive will be an H-Bot. It will be similar to the midTbot, but the motors are at the ends of the X axis. It will be fully enclosed, but I not started work on that part yet.
Disc Feed System
I hope to be able to use a single hobby servo to handle the loading and unloading of the blanks. The servo will control a sliding device that has three positions.
In the first position it acts like a support shelf for the disc. The bed slides under the feed tube and a disk drops into the pocket.
The next position is the clamping position. This holds the disc still while engraving.
The final position retracts the shelf so the disc drops through.
Electronics
The goal is to use a low cost controller like an Arduino Nano.
(2) Stepper motors for the X,Y motion
(1) Hobby servo for the disc feed system (PWM)
(1) Laser power control (PWM)
(2) homing switches
(1) interlock switch loop if there is a door and/or cover
Status
The major new feature of this design is the disc feed system, so I am primarily working on that right now.
If you want to be notified of future blog posts, please subscribe.
A lot of people have asked about building their own Coasty Laser Cutter. It takes a lot of work to get the files ready for release. I will release the source files in stages as they are ready so people can get started. Watch this post for updates. Subscribing to this blog or following me on Twitter (@buildlog) is a good way to keep up.
When everything is ready, I’ll probably also post on Thingiverse.
3D Printed Parts
Here are the STL files for the 3D printed parts. The parts are generally pretty easy to print. They require no support and can be printed in low resolution. I print at 0.28mm layer height. You need to watch out for warping on the chassis and front door. If the chassis warps it will stress the PCB and could damage some parts. The door needs to be flat in order to close properly.
I printed my parts in generic PLA. They printed fine, but if you have some crappier PLA or if you don’t have a heated bed, you should probably print with a brim. I would suggest printing the chassis first. If you can print that, the other parts are easier. I have some PETG on order to test. That supposedly warps less that PLA.
The holes used for the 8mm rods are designed to be a press fit. If the rods are hard to install, try cleaning the holes up a little by hand with a 5/16 or 8mm drill. The drive shaft bearing is also a tight fit. Try using a vise or clamp to press it into the chassis.
Here are some updates to Coasty – The Coaster Toaster, the tiny laser cutter specifically designed to cut drink coasters.
New Traction Roller
I made the traction roller diameter a lot smaller and moved it behind the beam. A smaller roller has a lot of advantages. It allows the beam to be closer to the contact points of the rubber orings. This improves the usable work area, because you can get closer to the edge of the coaster. With a smaller diameter the coaster travels less per revolution. This increases the torque and resolution.
Smaller Chassis
The chassis is now about 16mm smaller in depth due to the smaller roller and new location. The depth of the machine is quite a bit smaller than the coaster.
Fan Guard and Carbon Filter
I added a fan cover on the back. This acts as a finger guard and also allows a few layers of carbon filter cloth to be used. Bulk carbon filter cloth for use in air purifiers can be purchased on Amazon very cheaply. It removes a good portion of the odor of the smoke.
Carbon Filter Cloth
Door Interlock Switch
There is now a switch that cuts all power to the laser when the door is opened. You can still run the machine to test the motors, homing etc, the the beam cannot turn on with the door open.
IR Coaster Detector
I was not happy with the coaster homing switch used on the first version. While it never failed, it did not appear to be very robust and it caused some drag on the coaster. I changed to a IR LED and photo diode. When the light from the LED hits the photo diode, it conducts to the +5V. When the coaster blocks the light, it is pulled down to ground. I used a pot on the pull down because it did not know what he exact value would be. It turns out the value needs to be about 40k. The only catch was the microcontroller input pin pull up resistor on the Nano could not not used because it is less than the 40k. This required a slight hack to Grbl because Grbl is all or nothing on the pull ups for the limit switches.
I was not sure if ambient light changes might be a problem, like bright sunlight. The photo diode looks down and that appears to be good enough to avoid overhead light. I also have a mounting screw there in case I need to add a little shade/cover.
IR LED / Photo Diode Circuit
Bluetooth
I have been using Bluetooth on some other machines and really like it. Skipping USB cords and using a phone instead of a computer is great. I have found it to be very reliable. The real world bandwidth appears to be a little lower than 115200 USB. It has not been a problem, but I don’t do much gray scale engraving on this machine which needs higher bandwidth. Regardless, USB is still an option.
A standard HC-05 or HC-06 module plugs into a right angle connector.
Video
Here is a video of this version.
If you want to be notified of future blog posts, please subscribe.
I have been playing with the ESP32 microcontroller to see how well it would perform as a small scale CNC controller. The low cost and high performance as well as the built in Wifi and Bluetooth make it very attractive.
One of the challenges is step pulse timing. Most stepper drivers work with a direction signal and step signal. The step signals are a short pulse for each step. If they are too short, the driver will not detect them. If they are too long, it limits the rate at which you can send them.
You first set the direction signal high or low depending on the direction you want the motors to spin. You then send the step pulse. The direction signal has to be stable for a short period of time before the step signal is sent. The process is…
Set direction
Wait a bit (if it changed)
Turn on the step pulse signal.
Wait a bit
Turn off the step pulse signal.
The timing is critical and varies by motor driver. Here is a typical spec.
Here are the specs for a few of the stepper drivers I regularly use.
Allegro A4988
TI DRV8825
Toshiba TB6600
Direction Delay
200ns
650ns
?
Step Pulse Delay
1us
1.9us
2.2us
Test Firmware
Typically the firmware motion planner determines when to take a step, then sets an interrupt to occur at that time in the future. This allows the firmware to do other things like interacting with the user and planning future moves while it is waiting for the interrupt.
To simulate a stream of pulses, I created a timer interrupt that would case steps to occur at a constant 5kHz rate. That is onStepperDriverTimer() in the code.
In that interrupt service routine I first set the direction pin. Normally you only need to set it when the direction changes, but it will be easier to see this on a logic analyzer if I change it every time for this test. I then need to wait a little time before setting the step pulse pin. I could use another interrupt to do this, but the time is so short at about 750ns, that it is better to just waste a few cycles. In the CNC software I will only need to do this when the direction changes. That will be at the few beginning of the acceleration when the step rate is the slowest. I do this delay with a few NOP()s. The are “no operations”.
I then setup the the interrupt to end the pulse. That is onStepPulseOffTimer() in the code. I set the step pin after this because those instructions take clock cycles too. I can use those as part of my delay.
When that interrupt occurs, I turn off the step pulse signal. I also turn off the direction in this example. I am only doing it here so I can see that change on the logic analyzer. Normal CNC frmware would just leave it alone because there are typically thousands of steps before the direction is likely to change.
I wrote a program to simulate some CNC firmware so I could play with step pulse timing.
// create the hardware timers */
hw_timer_t * stepperDriverTimer = NULL; // The main stepper driver timer
hw_timer_t * stepPulseOffTimer = NULL; // This turns the step pulse off after xx uSeconds
// define the gpio pins
#define STEP_PIN 17
#define DIR_PIN 16
// the step pulse interrupt service routine.
void IRAM_ATTR onStepperDriverTimer()
{
// if ... the direction changed from last time (not in this demo)
digitalWrite(DIR_PIN, HIGH); // in actual CNC firmware this will go high or low
for(uint8_t i=0; i<10; i++)
{
NOP(); // do nothing for one cycle
}
// end if
// setup the pulse off timer
timerWrite(stepPulseOffTimer, 0);
timerAlarmWrite(stepPulseOffTimer, 22, false); // the alarm point is found by looking at logic analyzer
timerAlarmEnable(stepPulseOffTimer);
digitalWrite(STEP_PIN, HIGH); // put it after the timer setup to include the timeto do that
}
//
void IRAM_ATTR onStepPulseOffTimer()
{
digitalWrite(STEP_PIN, LOW); // end step pulse
digitalWrite(DIR_PIN, LOW); // only here for dem program CNC firmware would leave this until direction change
}
void setup() {
pinMode(DIR_PIN, OUTPUT);
pinMode(STEP_PIN, OUTPUT);
stepperDriverTimer = timerBegin(0, 4, true); // 80Mhz / 4 = 20Mhz// setup stepper timer interrupt ... this will simulate a flow of steps
stepPulseOffTimer = timerBegin(1, 1, true); //
// attach the interrupts
timerAttachInterrupt(stepperDriverTimer, &onStepperDriverTimer, true);// attach the interrupttimerAttachInterrupt(directionDelayTimer, &onDirectionDelayTimer, true);// attach the interrupt
timerAttachInterrupt(stepPulseOffTimer, &onStepPulseOffTimer, true);// attach the interrupt
// setup the time for the
timerAlarmWrite(stepperDriverTimer, 4000, true); // 20Mhz / 4000 = 5kHz rate ... this is the only one that auto repeats
timerAlarmEnable(stepperDriverTimer);
}
void loop() {
// no loop code required.:
}
Results
Here is a picture of my setup.
This is screen shot of what the logic analyzer captured. The upper line is the step signal and the lower line is the direction signal. The direction signal comes on first and then the step pulse signal comes on 0.75us later. The step pulse then lasts for about 2.5us before turning off.
Next Steps
I’ll go forward this method to see how well it works in actual CNC firmware.
I have been programming in the Arduino-ESP32 environment. This is an easy way to learn about the peripherals and do some quick tests. I may switch to the ESP-IDF in the future.
I would like to investigate the RMT features of the ESP32. It is designed for Remote Controls, but I have heard it is quite flexible and might help with pulse generation.
If you want to be notified of future blog posts, please subscribe.