Setting PWM prescale
Moderators: TomKerekes, dynomotion
Re: Setting PWM prescale
Ah, perfect, thanks!!
Re: Setting PWM prescale
I moved the command to begin serial communication to the program that I use to initialize my servos, which mostly works but seems to cause KFLOP to disconnect sometimes when I run it. I run the program from a button in KMotion CNC when I start up the the machine. Do you see something in this that would cause KFLOP to disconnect? You'll see the two lines that I added for starting serial at the top of int main().
Thanks!
Thanks!
- Attachments
-
- K2_Init Servo.c
- (11.11 KiB) Downloaded 100 times
Re: Setting PWM prescale
I also tried your code checking a persist variable to make sure the serial hadn't already been started, and KFLOP still disconnects. I also tried commenting out this new code to verify that it is causing the problem, and the program runs fine without it.
- TomKerekes
- Posts: 2677
- Joined: Mon Dec 04, 2017 1:49 am
Re: Setting PWM prescale
Hi amowry,
Please also post the "Driver\Defines.c" file.
What Version of KMotion are you using?
Please also post the "Driver\Defines.c" file.
What Version of KMotion are you using?
Regards,
Tom Kerekes
Dynomotion, Inc.
Tom Kerekes
Dynomotion, Inc.
Re: Setting PWM prescale
I'm using 4.34.
Here's the Defines.c
Here's the Defines.c
Re: Setting PWM prescale
One thing that is confusing to me is that the K2MC_driver.c program, which is flashed to KFLOP and runs at startup, includes a program called Init_Servo.c, which in turn has a function called init_board();. The driver program appears to call that function.
The program that initializes the servos, which I run by clicking a button in KMotion CNC, also contains the function init_board();, and appears to call the function again. I'm not sure why this function needs to be included twice, and appears to be called twice. I've attached all of these, in case they are useful. Sorry for all these questions
The program that initializes the servos, which I run by clicking a button in KMotion CNC, also contains the function init_board();, and appears to call the function again. I'm not sure why this function needs to be included twice, and appears to be called twice. I've attached all of these, in case they are useful. Sorry for all these questions
- Attachments
-
- K2_Init Servo.c
- (11.13 KiB) Downloaded 100 times
-
- Init Servo.c
- (10.37 KiB) Downloaded 95 times
-
- K2MC_driver.c
- (2.83 KiB) Downloaded 105 times
- TomKerekes
- Posts: 2677
- Joined: Mon Dec 04, 2017 1:49 am
Re: Setting PWM prescale
Hi amowry,
I'm not able to reproduce the problem. I tried Initializing over 100 times.
I suspect you are right in that it has to do with the other Flashed and running programs.
You didn't include information on what programs are loaded where, which are executing, or the other many included K2CNC files.
But most likely it has to do with the User Callback. If KFLOP is calling a callback function in a Thread, and any change to the Thread Program is made, there is a likely chance of a crash. Changes to code should not be made while the code is currently executing. The callback needs to be stopped first. See the StopCallback.c example. Note the callback can be called regardless of whether the Thread is currently executing or not. Note also the stop callback must usually be performed in a different Thread otherwise the stop callback will occur too late (when the code is executed after it has already been loaded/changed).
Its not clear why having duplicated code (init_board) in one program and also in another program would cause a problem.
If you provide how everything is organized and all the files I can try to figure it out.
I'm not able to reproduce the problem. I tried Initializing over 100 times.
I suspect you are right in that it has to do with the other Flashed and running programs.
You didn't include information on what programs are loaded where, which are executing, or the other many included K2CNC files.
But most likely it has to do with the User Callback. If KFLOP is calling a callback function in a Thread, and any change to the Thread Program is made, there is a likely chance of a crash. Changes to code should not be made while the code is currently executing. The callback needs to be stopped first. See the StopCallback.c example. Note the callback can be called regardless of whether the Thread is currently executing or not. Note also the stop callback must usually be performed in a different Thread otherwise the stop callback will occur too late (when the code is executed after it has already been loaded/changed).
Its not clear why having duplicated code (init_board) in one program and also in another program would cause a problem.
If you provide how everything is organized and all the files I can try to figure it out.
Regards,
Tom Kerekes
Dynomotion, Inc.
Tom Kerekes
Dynomotion, Inc.
Re: Setting PWM prescale
Thanks Tom-- I've attached the CallBack Servo.c file that is included in the driver program. That program, K2MC_driver.c, is the only thing flashed (thread 6, which runs at startup). Then, when I open KMotionCNC I run the K2_Init Servo.c program on thread 1.
I don't want to waste your time looking through all this stuff, so I think what I'll try first is moving the serial initialization code to the beginning of the K2MC_driver.c and re-flash that, so that serial will be started before the callback. It sounds like that might be a solution, correct? I'll report back after trying that, but it probably won't be today because I'm running a job and I don't want to restart the machine.
Thanks again!
-Andrew
I don't want to waste your time looking through all this stuff, so I think what I'll try first is moving the serial initialization code to the beginning of the K2MC_driver.c and re-flash that, so that serial will be started before the callback. It sounds like that might be a solution, correct? I'll report back after trying that, but it probably won't be today because I'm running a job and I don't want to restart the machine.
Thanks again!
-Andrew
- Attachments
-
- CallBack Servo.c
- (5.62 KiB) Downloaded 104 times
- TomKerekes
- Posts: 2677
- Joined: Mon Dec 04, 2017 1:49 am
Re: Setting PWM prescale
I moved the serial code to the driver program and reflashed it, and all seems to be working great now.
Thanks again for all your help. I must say, although K2 made some mistakes in terms of documentation and customer service (lack of both) I think they made a great decision choosing KFLOP, and I really appreciate your customer service! I know how much time that must take. Have a great weekend!
Thanks again for all your help. I must say, although K2 made some mistakes in terms of documentation and customer service (lack of both) I think they made a great decision choosing KFLOP, and I really appreciate your customer service! I know how much time that must take. Have a great weekend!