I just realized that the code you posted is your complete application. All you need to do is adding an #include "Arduino.h" at top of the file and adding the USB Host library to the project. It then compiles without an...
Did you include "arduino.h" in main.cpp? VisualTeensy is using plain cpp and does nothing behind your back (as one of its design goals). I.e., you need to include "Arduino.h", you need to forward declare functions and...
I did a draft of a Encoder Matrix Proto board. The idea is that one can start developing without the tedious wiring of a lot of encoders. After development the board can be easily cut or broken or extended to fit the...
I just had a look at the library code. You can simply attach a nullptr to remove the callback.
I.e.:
SpindleEnc.attachCallback(onEncoderChanged); // attaches onEncoderChanged to SpindleEnc...
Are you sure that you want to change the pitch while the spindle rotates? Thinking of the noise the breaking thread tool makes gives me goose bumps :-))
Seriously;
In your controlling application I'd require that...
See also here https://forum.pjrc.com/threads/70264-EncoderTool?p=306250&viewfull=1#post306250 for a proposal to read out 190 encoders with one Teensy, without additional hardware :-)
I was thinking of a simple shift register, but then I thought why bother with external parts, when a Teensy can directly read out the matrix even faster.
A quick calculation gives the following formulas for the...
That was easy ;-)
You print the current position in the encoder callback. At high encoder speeds the printing is not yet done when it tries to invoke the callback again. This will basically lock the system.
I moved...
The Error_Callback is a left over from development and it not working anymore. I'll remove the leftover code in the next update. The error callback was invoked whenever the internal state machine detects an A/B pattern...
Feel free to post your program or a link to it for a review. My experience is that you can stare for days at some code and don't find a bug while someone else with fresh eyes might see it in minutes.
It will use...
I thought you are interested if the spindle encoder code looses counts? So the stepper shouldn't be an issue for the test right? Just check if the encSim count equals the spindle counts your program detects.
Might...
Inspired by this https://forum.pjrc.com/threads/70233-Using-Teensy-for-big-MIDI-control-surface and the apparent lack of 23S17 IO Expanders I was thinking of yet another encoder multiplexing scheme which might handle...
Here you go :-)
A few links:
Repo: https://github.com/luni64/EncoderTool
Documentation: https://github.com/luni64/EncoderTool/blob/master/Documentation/Overview.md
Schematics:...
Oh, both variables c0 and c1 need to be int32_t not uint32_t. Sorry for the confusion (never post untested code :-))
Great, if it works just stick with it.
Take a second Teensy and upload one of th...
Just had a look at Octopart. There are plenty at "unsusal" suppliers. https://octopart.com/search?q=mcp23S17¤cy=USD&specs=0&in_stock_only=1 (click on "show all" below the standard distributor list)
Sure, something like this should work (untested, first value will be wrong)
#include "Arduino.h"
#include "EncoderTool.h"
using namespace EncoderTool;
Encoder spindleEnc;
IntervalTimer speedTimer;
Here an example how to use a MCP23S17 to read out encoders with the EncoderTool (working example here: https://github.com/luni64/EncoderTool/tree/master/examples/2_multiplexing/multiplexed_MCP23S17). If you want to use...
The nice thing about this approach is, the whole thing runs completely in the background. Your foreground code can do whatever it wants, as long as it doesn't disable interrupts your leadscrew will magically follow your...
If you don't find a possibility to do non blocking writes to the display you might consider a different approach:
If you can assure that the number of encoder counts per spindle rev is always more than the number of...
Yes, I just looked through my stock of bought but never used parts and found a couple of 23S017. Starting to rain here. So, extending the EncoderTool might be a nice weekend project :-)
Discussions about encoder readout strategies seem to always end up like windows vs. linux discussions :-)
I'm the author of the EncoderTool library which, to avoid those discussions, supports both strategies :-). As...
Thanks for the shout out but the TimerTool only uses the timing functions, counting is a different thing. I recommend manitous collection of snippets https://github.com/manitou48/teensy4 instead. You will probably find...
Thanks, I'll have a look. But this will take some time (working on another project currently...)
Quick Idea, can you change the GPT1/GPT2 to PIT and see if it works then?
setPeriod changes the period immediately. I.e., it will end the current period and restart the timer with the new period. setNextPeriod is supposed to set a new period after the current one is done to prevent partial...
Ups, thought I had changed them all. Thanks for spotting this.
You change the period by t1.setPeriod(...)
Great, hope you show the progress here. At least I'd be very interested.
Long time ago I was...
I just saw that you are using the depricated Timer API. You should have got a corresponding warning from the compiler!
Instead of
Timer t1(GPT1);
say
PeriodicTimer t1(GPT1);
If you tell me where you have problems to understand it I can try to explain. Your code basically does the same but a bit more verbose.
You can use both GPT1 or GPT2. Setting it to 150MHz will certainly improve...
Not a good idea to ask the same question in two threads....
see here: https://forum.pjrc.com/threads/59112-TeensyTimerTool?p=305466&viewfull=1#post305466 for an answer
Your code is a bit convoluted. The problems you get are probably due to the short period and the relatively (to the calling period) long blocking in the callbacks.
I'd do something like this:
#include...
Whatever timer you use, the drift will always be the drift of the corresponding crystal (IIRC: ~20ppm). If you need less you might be better off with a clock module like this one...
As mentioned in #2 you must not call a move command while the motor is still moving. The code in #1 calls moveAsync every 2 seconds regardless if the motor moves or not. -> the movement will be disturbed every 2...
It is running from a timer interrupt. I.e., the moveAsync() sets up all parameters for the movement and starts a timer which generates the pulses, adjusts the timing as needed and keeps track of the steps in its...
moveAsync is not blocking (hence the name). In loop you call moveAsync every 2 seconds, i.e. you call moveAsync while the motor still runs which will mess up the controller. Try using controller.move(motor) (which...
Looks like you are using a stock gcc compiler. Teensyduino expects some math libs copied into the gcc folders. See here https://github.com/TeensyUser/doc/wiki/GCC#switching-between-different-toolchains what you need to...
Please test and let me know if it works for you before I push it to the master branch.
As defragster mentioned, all TCK timers (TCK, TCK64, TCK_RTC) run from yield. Anyway, I never had issues printing small...
Pushed a test version to the RemainingTime branch. Here a usage example:
#include "TeensyTimerTool.h"
using namespace TeensyTimerTool;
OneShotTimer t1(TCK64);
volatile bool start = true;
Looks like you want a timer interrupt? If so, use the IntervalTimer which is the native timer for all ARM Teensies.
IntervalTimer t1;
void onTimer()
{
digitalToggleFast(LED_BUILTIN);
}
I had a closer look at the StreamUtils library which is quite nice. The StringStream is really useful for converting printables like a crashreport to Strings:
#include "StreamUtils.h"
void setup()
{
if...
Yes, the streamUtils library seems to be an overkill for this. (However the library looks very interesting for other stuff).
The code shown in #3 could be done much simpler, unfortunately a bug sneaked into the...
Actually CrashReport derives from Printable not Stream. Anyway, you can easily capture the content of a printable object with the following helper class. The constructor of the StringDumper "prints" the content of the...
TimerOne is a compatibility wrapper around the native IntervalTimer. So, unless you need to write code compatible to AVR you'd be better of with an IntervalTimer. This code generates a 50µs pulse every 1000µs:
...
I added a helper class which automatically maintains a list of all currently existing instances of a class to my TeensyHelpers repository.
Such a thing comes in handy if you design a class which requires the user to...
Comparing the addresses of the port objects as you did is perfectly OK. The only 'drawback' (if at all) is, that it needs to be done at runtime (if the compiler is not able to optimize it away...)
Actually those...
Reading out encoders and communicating the values to the PC are two completely different stories. You don't need to add 16 encoders to the 4067, 8 will work just as well. Or you use the 4051 which is a 8bit version....
Using the EncoderTool (https://github.com/luni64/EncoderTool) you can easily multiplex rotary encoders and their pushbuttons which reduces the number of needed digital pins significantly. Here some examples, schematics...