Teknic Clearcore with Arduino wrapper rotary table

Thanks in advance! I'm extremely new to Arduino and Clearcore, with little to no programing experience(this means I have none). Short story on the scope of project - Servo mounted to a rotary table, controlled by manual buttons such as Jog CW, Jog CCW, Rapid CW... you get the idea. Basically a power feed for a rotary table. I can get the IDE to talk to the Clearcore using teknic's built in example of writedigitaloutput, it will then change the LED flashing pattern. Any code after that will not work, and I get a similar error. This code is from ChatGPT, just an example of code with the corresponding error. I get this error while trying to verify. Please let me know what I'm missing here, I'm sure I've overlooked something. Thanks again!

The Clearcore is an IO expansion and motion controller that works in addition to the Teknic servo with built in controller. The Clearcore can be programmed with C++ or Arduino code, with their Arduino wrapper and Arduino IDE.

As of now there is no wiring schematic involved, the Clearcore is connected to the computer via USB.

Here are some links about the Clearcore and information they have provided about programing with Arduino.

https://teknic.com/
https://teknic.com/products/io-motion-controller/
https://teknic-inc.github.io/ClearCore-library/ArduinoRef.html


#include <Servo.h> 

Servo myservo;  // Create a Servo object
int speed = 100;  // Desired rotation speed in rpm
int servoDirection = 1;  // 1 for CCW, -1 for CW

int buttonPin = 2;  // Connect your button to digital pin 2
int buttonState = 0;
int lastButtonState = 0;

void setup() {
  myservo.attach(9);  // Attach the servo to pin 9
  myservo.writeMicroseconds(1500);  // Set the initial position (1500 is the stop position for a modified servo)
  
  pinMode(buttonPin, INPUT);
  lastButtonState = digitalRead(buttonPin);
}

void loop() {
  buttonState = digitalRead(buttonPin);
  
  if (buttonState == HIGH && lastButtonState == LOW) {
    // Button has been pressed, toggle the servo direction
    servoDirection = -servoDirection;
  }

  lastButtonState = buttonState;

  // Calculate the angle increment based on speed (in degrees per second)
  float angleIncrement = 6.0 * speed / 60.0 * servoDirection;

  // Move the servo by the calculated angle increment
  myservo.write(myservo.read() + angleIncrement);

  delay(20);  // Adjust the delay to control the rotation speed
}

Here's the error


C:\Users\freda\AppData\Local\Arduino15\libraries\Servo\src\sam\Servo.cpp: In function 'void Servo_Handler(timer16_Sequence_t, Tc*, uint8_t)':
C:\Users\freda\AppData\Local\Arduino15\libraries\Servo\src\sam\Servo.cpp:79:9: error: 'union Tc' has no member named 'TC_CHANNEL'
     tc->TC_CHANNEL[channel].TC_SR;
         ^~~~~~~~~~
C:\Users\freda\AppData\Local\Arduino15\libraries\Servo\src\sam\Servo.cpp:81:13: error: 'union Tc' has no member named 'TC_CHANNEL'
         tc->TC_CHANNEL[channel].TC_CCR |= TC_CCR_SWTRG; // channel set to -1 indicated that refresh interval completed so reset the timer
             ^~~~~~~~~~
C:\Users\freda\AppData\Local\Arduino15\libraries\Servo\src\sam\Servo.cpp:81:43: error: 'TC_CCR_SWTRG' was not declared in this scope
         tc->TC_CHANNEL[channel].TC_CCR |= TC_CCR_SWTRG; // channel set to -1 indicated that refresh interval completed so reset the timer
                                           ^~~~~~~~~~~~
C:\Users\freda\AppData\Local\Arduino15\libraries\Servo\src\sam\Servo.cpp:81:43: note: suggested alternative: 'TCC1_SWAP'
         tc->TC_CHANNEL[channel].TC_CCR |= TC_CCR_SWTRG; // channel set to -1 indicated that refresh interval completed so reset the timer
                                           ^~~~~~~~~~~~
                                           TCC1_SWAP
C:\Users\freda\AppData\Local\Arduino15\libraries\Servo\src\sam\Servo.cpp:90:13: error: 'union Tc' has no member named 'TC_CHANNEL'
         tc->TC_CHANNEL[channel].TC_RA = tc->TC_CHANNEL[channel].TC_CV + SERVO(timer,Channel[timer]).ticks;
             ^~~~~~~~~~
C:\Users\freda\AppData\Local\Arduino15\libraries\Servo\src\sam\Servo.cpp:90:45: error: 'union Tc' has no member named 'TC_CHANNEL'
         tc->TC_CHANNEL[channel].TC_RA = tc->TC_CHANNEL[channel].TC_CV + SERVO(timer,Channel[timer]).ticks;
                                             ^~~~~~~~~~
C:\Users\freda\AppData\Local\Arduino15\libraries\Servo\src\sam\Servo.cpp:97:18: error: 'union Tc' has no member named 'TC_CHANNEL'
         if( (tc->TC_CHANNEL[channel].TC_CV) + 4 < usToTicks(REFRESH_INTERVAL) ) { // allow a few ticks to ensure the next OCR1A not missed
                  ^~~~~~~~~~
C:\Users\freda\AppData\Local\Arduino15\libraries\Servo\src\sam\Servo.cpp:98:17: error: 'union Tc' has no member named 'TC_CHANNEL'
             tc->TC_CHANNEL[channel].TC_RA = (unsigned int)usToTicks(REFRESH_INTERVAL);
                 ^~~~~~~~~~
C:\Users\freda\AppData\Local\Arduino15\libraries\Servo\src\sam\Servo.cpp:101:17: error: 'union Tc' has no member named 'TC_CHANNEL'
             tc->TC_CHANNEL[channel].TC_RA = tc->TC_CHANNEL[channel].TC_CV + 4;  // at least REFRESH_INTERVAL has elapsed
                 ^~~~~~~~~~
C:\Users\freda\AppData\Local\Arduino15\libraries\Servo\src\sam\Servo.cpp:101:49: error: 'union Tc' has no member named 'TC_CHANNEL'
             tc->TC_CHANNEL[channel].TC_RA = tc->TC_CHANNEL[channel].TC_CV + 4;  // at least REFRESH_INTERVAL has elapsed
                                                 ^~~~~~~~~~
C:\Users\freda\AppData\Local\Arduino15\libraries\Servo\src\sam\Servo.cpp: In function 'void _initISR(Tc*, uint32_t, uint32_t, IRQn_Type)':
C:\Users\freda\AppData\Local\Arduino15\libraries\Servo\src\sam\Servo.cpp:109:5: error: 'pmc_enable_periph_clk' was not declared in this scope
     pmc_enable_periph_clk(id);
     ^~~~~~~~~~~~~~~~~~~~~
C:\Users\freda\AppData\Local\Arduino15\libraries\Servo\src\sam\Servo.cpp:111:4: error: 'TC_CMR_TCCLKS_TIMER_CLOCK3' was not declared in this scope
    TC_CMR_TCCLKS_TIMER_CLOCK3 | // MCK/32
    ^~~~~~~~~~~~~~~~~~~~~~~~~~
C:\Users\freda\AppData\Local\Arduino15\libraries\Servo\src\sam\Servo.cpp:112:13: error: 'TC_CMR_WAVE' was not declared in this scope
             TC_CMR_WAVE |                // Waveform mode
             ^~~~~~~~~~~
C:\Users\freda\AppData\Local\Arduino15\libraries\Servo\src\sam\Servo.cpp:112:13: note: suggested alternative: 'REG_TCC1_WAVE'
             TC_CMR_WAVE |                // Waveform mode
             ^~~~~~~~~~~
             REG_TCC1_WAVE
C:\Users\freda\AppData\Local\Arduino15\libraries\Servo\src\sam\Servo.cpp:113:13: error: 'TC_CMR_WAVSEL_UP_RC' was not declared in this scope
             TC_CMR_WAVSEL_UP_RC );       // Counter running up and reset when equals to RC
             ^~~~~~~~~~~~~~~~~~~
C:\Users\freda\AppData\Local\Arduino15\libraries\Servo\src\sam\Servo.cpp:113:13: note: suggested alternative: 'TCC_WAVE_POL0'
             TC_CMR_WAVSEL_UP_RC );       // Counter running up and reset when equals to RC
             ^~~~~~~~~~~~~~~~~~~
             TCC_WAVE_POL0
C:\Users\freda\AppData\Local\Arduino15\libraries\Servo\src\sam\Servo.cpp:110:5: error: 'TC_Configure' was not declared in this scope
     TC_Configure(tc, channel,
     ^~~~~~~~~~~~
C:\Users\freda\AppData\Local\Arduino15\libraries\Servo\src\sam\Servo.cpp:116:5: error: 'TC_SetRA' was not declared in this scope
     TC_SetRA(tc, channel, 2625); // 1ms
     ^~~~~~~~
C:\Users\freda\AppData\Local\Arduino15\libraries\Servo\src\sam\Servo.cpp:121:9: error: 'union Tc' has no member named 'TC_CHANNEL'
     tc->TC_CHANNEL[channel].TC_IER = TC_IER_CPAS;
         ^~~~~~~~~~
C:\Users\freda\AppData\Local\Arduino15\libraries\Servo\src\sam\Servo.cpp:121:38: error: 'TC_IER_CPAS' was not declared in this scope
     tc->TC_CHANNEL[channel].TC_IER = TC_IER_CPAS;
                                      ^~~~~~~~~~~
C:\Users\freda\AppData\Local\Arduino15\libraries\Servo\src\sam\Servo.cpp:121:38: note: suggested alternative: 'ICM_IER_MASK'
     tc->TC_CHANNEL[channel].TC_IER = TC_IER_CPAS;
                                      ^~~~~~~~~~~
                                      ICM_IER_MASK
C:\Users\freda\AppData\Local\Arduino15\libraries\Servo\src\sam\Servo.cpp:124:5: error: 'TC_Start' was not declared in this scope
     TC_Start(tc, channel);
     ^~~~~~~~
C:\Users\freda\AppData\Local\Arduino15\libraries\Servo\src\sam\Servo.cpp: In function 'void finISR(timer16_Sequence_t)':
C:\Users\freda\AppData\Local\Arduino15\libraries\Servo\src\sam\Servo.cpp:154:5: error: 'TC_Stop' was not declared in this scope
     TC_Stop(TC_FOR_TIMER1, CHANNEL_FOR_TIMER1);
     ^~~~~~~

exit status 1

Compilation error: exit status 1

Welcome to the forum.

You might want to look at this How to get the best out of this forum before you proceed any further.

Need to supply both code and schematic, as well as saying what processor you are trying to use for the code.

Be aware that ChatGPT can't really write code at all. It just gives you a mashup of things it finds on the net. The problem is that in order to use ChatGPT you have to know how to read code at least.

You are also using the word "Clearcore" and I am sure not many people here know what that is. So could you include a link that explains what it is.

Grumpy_Mike, Thanks for the welcome, and information. I went back and added more information to the original post. I'm aware of the ChatGPT not being efficient at writing code, I did try several online tutorials prior with no luck. They all seem to have a similar error.

Yes that is because it is trying to do something that is impossible.

I was hoping for some information on your servos, but there was none.

There are two types of servos.

  1. The normal type that will go to a specific position when you command it to. This is over a limited range of angles in the region of about 120˚ or so.

  2. Servos that have been modified to remove the feedback pot in them so they rotate continuously. These are called unsurprisingly continuously rotating servos, and will not go to a specific position.

You can't do both go to a position and continuously rotate them.

The code is trying to do both.

Ok let's assume you have a continuous rotation type. The speed is set by the number you write that is past the point where they are stationary. This is set by the line:-

and you modify this number until you get it to stop.

Then when you come to move them then this bit of code is useless:-

Because you can't move a continuous rotating servo to a specific angle.

What you have to do to control the speed is to use the value you used in the writeMicroseconds that you found it would stop and add or subtract a number from this value, the bigger the number the faster it will go, and add will make it go in one direction and subtract in the other.

It is not a matter of efficiency, it is the fact that it has no concept of context. And would not know what you are asking it to do is impossible.

Did you understand what the tutorials were trying to do?

Please forget ChatGPT for the purposes of this discussion. It's just adding unnecessary noise.
If you don't know how to program, then you'll have to learn, or find someone to do this for you.

I've found Teknic's documentation to be very clear and simple to follow. I'd say that they are by far the easiest of the motor controllers to use and don't require days of banging your head against the wall (I'm looking right at you, Advanced Motion Systems!). Granted, I've done that using a PC to interface, but that shouldn't matter.

The code you are using is trying to interface to an Arduino servo object and failing. It has nothing at all to do with Teknic or Clearpath. This note from Teknic is telling:

The Servo and Stepper Arduino libraries are not supported by ClearCore. For motor control, defer to the underlying ClearCore I/O and Motion Control library.

Sorry I forgot to include the link for that as well
https://teknic.com/model-info/CPM-SDSK-3421S-RLN/

I did understand but after you and cedarlakeinstruments replied, it seems that my understanding of the programing language was completely off. I'm going to play around some more tonight and see what I can figure out.

Thank you for this information, it makes way more sense why nothing has worked correctly. I did read through all the teknic information but being new to programing language it all ran together.

So it looks like this is not a servo at all. From my reading of the information this is a stepping motor. No wonder nothing will work. Even real intelligence would fail given your description of what you had.

I didn't read the documentation, but from my (limited: I just used them for one project) experience, Teknic offers closed-loop servomotor and stepper controllers that behave pretty much the same way. Just not like what arduino means by "servo" :grinning:

Question for OP. What led you to use Teknic? Nothing wrong with them: as I said earlier, I really enjoyed the one project I did with ClearPath and it went very smoothly. However, there are other closed loop motor controllers that are specifically designed for the arduino ecosystem that may be easier to use. Also, if you check cnczone.com, you'll find prebuilt systems for adding electronic indexing to rotary tables that are ready to run.
And of course, there's always grbl and its associated free UI's which require no programming at all.

In short, there are already many arduino-compatible solutions that would probably provide a simpler path for you.

I had been researching for a bit before pulling the trigger on this system, and there were a few selling points for me.

An engineer I've worked with recommended them, he uses them for quite a few different projects and had great things to say from quality to customer service. With the customer service I had requested information on their site and within a day a rep called and spent 15 mins or so going over my project and led me to the correct parts for my application. He also followed up with a detailed email with several links for programing tips/tutorials(didn't get me far but I'm a touch slow with some things).

The system I chose seemed to fit my project the best without getting too deep in the weeds. Teknic makes it very easy for a newbie to find what they are looking for. Spending time on websites like automation direct didn't seem to get me anywhere cause I really didn't know what's compatible and what I needed without doing a super deep dive. Like most project there is a time crunch, which I'm hitting now...

Some of the ready to run systems didn't offer enough control for me or were way too much. I need more than adjustable rpm and direction, but not a full CNC set up which is basically what I ended up doing :man_facepalming:

You really should.

You will find that the input to the motors is a step and direction signal. Which in my book is a stepping motor and not a servo.

That happens a lot especially on over price equipment. Try asking for details on some high end laser cutters and you get the same treatment.

Did this "sales engineer" actually call it a servo?

A lot of motor drives use that method to maintain compatibility between servo & stepper interfaces. Different drive same interface method means less hardware to inventory.

I honestly don't know what the drive interface to the Teknic servo (yes, it was a servo not a stepper) I used has since I interfaced to it with USB.

The difference is that anytime I've dealt with Amada, Trumpf, Mits is that those reps are getting a commission. They get a big rip for a 250k sale, while the Teknic Applications Engineer was not linked to my sale in any way.

Yes he did.

The fact 5at you can't get any servo code to work shows you there is at least a vocabulary miss match between what you have and what the rest of the world calls it.

Good luck with your project
. Goodbye.

Anyways, cedarlakeinstruments if you have any more information such as YouTube clips, or other forum posts that pertain to Teknic "servo" code for manual controls it would be much appreciated. Ive made a lot of strides in the past few days but still have a couple road blocks. Thanks for your help.

moderator edit: ad hominem removed

Sorry, I don't. I don't find videos very helpful for stuff like this. Does Teknic have a forum where you can ask specific questions?

They don't, not that I've found at least. As I get closer to my deadline with this if I can't get it going is this something your company would be interested in programing?

Sure. Just send me a PM if you want to discuss it.

1 Like

Hello fredainc,
Maybe my answer is a bit off topic, but I do have a rotary table, driven by a stepper motor, (not a servo), and an Arduino UNO, but I can let it move in de ways you're describing. I found the solution to tackle this on: Snailworks Electronic Index Build Log. Information about the hardware + Arduino sketches can be found here.
It is worthwhile to look around in CNC orientated sites.

Thank you for the info, I'll go through it and see if anything will help me.