Kogna +/- 15V Enable Bit

Moderators: TomKerekes, dynomotion

Post Reply
jtremel
Posts: 39
Joined: Fri Jun 21, 2019 10:55 pm

Kogna +/- 15V Enable Bit

Post by jtremel » Wed Apr 19, 2023 6:31 pm

If I understand the documentation, IO Bit 279 needs to be set to enable the onboard +/-15V generators and get the DAC voltages driven to the output pins on JP8.

Every attempt I have made to set this bit results in the Kogna disconnecting from Kmotion. When communications re-establishes, Bit 279 is off.
I have attempted to set Bit279 with the following methods:
  • Checking the box "EN +/-15V" in the Kogna Tab of the Digital IO screen
  • Sending a "SetBit279" Console Command
  • Running a C-program that has a SetBit(279) call
Volt meter readings verify the DAC output stage is not correctly driving the pins on JP8 (I only tried DAC8/JP8 Pin25).

User avatar
TomKerekes
Posts: 2676
Joined: Mon Dec 04, 2017 1:49 am

Re: Kogna +/- 15V Enable Bit

Post by TomKerekes » Wed Apr 19, 2023 6:45 pm

Hi Jim,

How is Kogna being powered? The +/-15V generator and analog amplifiers require more power than 500ma USB can provide. Try an external +5V supply or connect the USB to a power adapter that can provide 1A or more.
Regards,

Tom Kerekes
Dynomotion, Inc.

jtremel
Posts: 39
Joined: Fri Jun 21, 2019 10:55 pm

Re: Kogna +/- 15V Enable Bit

Post by jtremel » Wed Apr 19, 2023 7:23 pm

Hi Tom,

I am currently powering from a 5V / 2amp power adapter connected to the micro-usb (J3).
I will hunt down a molex connector and another 5V supply to try powering from JR1.

jtremel
Posts: 39
Joined: Fri Jun 21, 2019 10:55 pm

Re: Kogna +/- 15V Enable Bit

Post by jtremel » Wed Apr 19, 2023 8:09 pm

Tom - that was indeed the problem.

I am now suppling power through JR1 (with a different PS) and that corrected the issue. I am now able to enable bit 279 and have verified correct voltages on JP8.

I feel a little silly for not trying that before posting :oops:

As a side note. I have noticed a few other things .NET related.
1)
If I try to compile a program through the .NET dll with a call to KM.Compile() or KM.CompileAndLoadCoff() - and the program has a bug that causes a compile error - the entire process will crash immediately - terminating all windows with no chance to catch an exception.
Compiling through Kmotion.exe interface works as expected.

2)
KM.WriteLineWithEcho(cmd) also seems to crash the process on any cmd that will generate a mult-line response ("GetStatus", "GetGatherHex 0 100".

Neither issue is a huge deal to me right now as I have work-arounds in both cases.

User avatar
TomKerekes
Posts: 2676
Joined: Mon Dec 04, 2017 1:49 am

Re: Kogna +/- 15V Enable Bit

Post by TomKerekes » Wed Apr 26, 2023 1:04 am

Hi Jim,
If I try to compile a program through the .NET dll with a call to KM.Compile() or KM.CompileAndLoadCoff() - and the program has a bug that causes a compile error - the entire process will crash immediately - terminating all windows with no chance to catch an exception.
Compiling through Kmotion.exe interface works as expected.
I can't reproduce this. I run the SimpleForms example and use it to Compile a program with a bug and it works as expected. Please try that and possibly supply an example of exactly what code you are using.
KM.WriteLineWithEcho(cmd) also seems to crash the process on any cmd that will generate a mult-line response ("GetStatus", "GetGatherHex 0 100".
I think that is somewhat as to be expected. The WithEcho version shouldn't be used with an App to send commands. There isn't any need for an echo back to an App. And to do this with a command with a response the Libraries should be locked and then after the command all the responses should be read back before the libraries are released.
Regards,

Tom Kerekes
Dynomotion, Inc.

jtremel
Posts: 39
Joined: Fri Jun 21, 2019 10:55 pm

Re: Kogna +/- 15V Enable Bit

Post by jtremel » Wed Apr 26, 2023 9:43 am

HI Tom,

For the the c file test I started with BlinkKflop.c and added a line of garbage code that can be uncommented to produce a compile error.

Code: Select all

[#include "KMotionDef.h"

void main() 
{
	//garbagecodetest
	int i;
	for (i=0; i<10; i++)
	{
		ClearBit(46);
		Delay_sec(0.1);
		SetBit(46);
		Delay_sec(0.1);
	}
}
Everything works as expected when compiled with the vaild c code.

SimpleForms Behavior
When //garbcodetest is uncommented and I try to compile/run from SimpleForms I get a "Microsoft Visual C++ Runtime Library" error message and then the process shuts down - terminating the program and all windows.

I'll have to figure out how to post pictures, but the Error message box says:

Code: Select all

Debug Assertion Failed!
Program:
C:\Kmotion5.0.6\Kmotion\Debug\SimpleFormsCS.exe
File:
minkernel\crts\ucrt\inc\corecrt_inteneral_string_templates.h
Line: 81
Expression: (L"Buffer is too small" && 0)
The message box button options are Abort/Retry/Ignore. Regardless of which button is used to acknowledge the dialog, the behavior is an immediate termination of the windows process:
Interrogating the debug console, the termination code is found:
The program '[8748] SimpleFormsCS.exe' has exited with code 3221226505 (0xc0000409).

My C# Application Behavior
Interestingly, when I run the same test from my C# application I DO NOT get the "Microsoft Visual C++ Runtime Library" error message. The process just quietly exits with the same debug console termination code:
The program '[9540] KognaTemplateApp.exe' has exited with code 3221226505 (0xc0000409).

My C# code is very similar to the SimpleForms example

Code: Select all

        /// <summary>
        /// Compile a C program (from file path given) and execute (on the thread passed in) 
        /// </summary>
        /// <param name="strFileName">Full file name and path of .c file </param>
        /// <param name="threadNum">Thread numnber to execute program on (1 to 7 are valid numnbers)</param>
        public bool CompileLoadExecute(string strFileName, int threadNum)
        {
            if (!Connected)
                return false;
            try
            {
                string Result = KM.CompileAndLoadCoff(threadNum, strFileName, false);
                if (Result != "")
                {
                    MessageBox.Show(Result, "Compile Error");
                    return false;
                }
                else
                {
                    // everything ok, execute the Thread
                    string strExec = "Execute" + threadNum.ToString();
                    SendConsoleCommand(strExec);
                    return true;
                }
            }
            catch (DMException ex)
            {
                MessageBox.Show(ex.InnerException.Message);
                return false;
            }
        }

Code: Select all

        /// <summary>
        /// use this method to send console commands to the board.  It checks for connection and wraps the KM.WriteLine call in Try/Catch....
        /// </summary>
        public bool SendConsoleCommand(string cmd)
        {
            if (Connected == false)
                return false;

            try
            {
                KM.WriteLine(cmd);
                return true;
            }
            catch (KMotion_dotNet.DMException ex)
            {
                GScommon.DebugLog.Write(ex.Message + ":" + ex.StackTrace);
                return false;
            }
            catch (Exception e)
            {
                GScommon.DebugLog.Write(e.Message + ":" + e.StackTrace);
                return false;
            }
        }
In previous Kflop releases, the same code would produce a messagebox that there was a compile error, but application would not crash.


Calling TCC Command Line Interface

From my C# application, I also have coded the ability to call l the TCC compiler's CLI directly:

Code: Select all

        /// <summary>
        /// call up the TCC67 command line interface to compile a c code file
        /// </summary>
        /// <param name="file2compile">the full name/path of the  .c code to compile </param>
        /// <param name="threadNumber">the thread that the compiled coff file is intended to be run on </param>
        public static void complileKogna(string c_file_name, int threadNumber)
        {
            if (File.Exists(c_file_name) == false)
            {
                //TODO:
                //AppLog.Write("No File Selected... aborting compile");
                return;
            }

            string coffname = Get_Coff_Name_From_C_file(c_file_name, threadNumber);
            string c_path = Path.GetDirectoryName(c_file_name);

            //create the bin directory if needed
            if (Directory.Exists(Path.GetDirectoryName(coffname)) == false)
            {
                string dir2create = Path.GetDirectoryName(coffname);
                Directory.CreateDirectory(dir2create);
                System.Threading.Thread.Sleep(100);
            }

            //read in user settings
            string exe_path = GS.Dynomotion.mdl_DynoAppSettings.TCC_exe.Value;
            string dsp_file = GS.Dynomotion.mdl_DynoAppSettings.DSP_out_file.Value;
            string dsp_include = Path.GetDirectoryName(dsp_file);

            //build up the argument list
            string compileArgs = "-text " + threadAddressKogna[threadNumber] + " -g -nostdinc ";
            compileArgs += "-I " + quote(dsp_include) + " ";
            compileArgs += "-I " + quote(c_path) + " ";
            compileArgs += "-o " + quote(coffname) + " " + quote(c_file_name) + " " + quote(dsp_file);

            //procCompile=System.Diagnostics.Process.Start(compiler_path, compileArgs);
            procCompile = new System.Diagnostics.Process();
            procCompile.StartInfo.FileName = exe_path;              // set compiler path
            procCompile.StartInfo.Arguments = compileArgs;          // add arguments
            procCompile.StartInfo.UseShellExecute = false;          // Set UseShellExecute to false for redirection.
            procCompile.StartInfo.RedirectStandardOutput = true;    // Redirect the standard output of the sort command.
            procCompile.StartInfo.RedirectStandardError = true;     // Redirect the standard output of the sort command.

            // some diagnostic output
            GScommon.DebugLog.Write("Running Compiler: " + exe_path);
            GScommon.DebugLog.Write("  -args: " + compileArgs);

            procCompile.Start();                                    // start the compile process
            StreamReader stdReader = procCompile.StandardOutput;    // hook into the standard output stream
            StreamReader errReader = procCompile.StandardError;     // hook into the stardard error stream (this is actually where messages come in)

            // wait till the compiler is finished
            while (procCompile.HasExited == false) { /* just hang tight */ };

            //output the compiler results
            GScommon.DebugLog.Write("Compiler returned with exit code: " + procCompile.ExitCode);
            string s = stdReader.ReadToEnd();
            s += errReader.ReadToEnd();

            // if there was a compile error, jump out here without reading the coff
            if (procCompile.ExitCode != 0)
            {
                GScommon.DebugLog.Write("Compiler Returned an eror:\r\n" + s);
                return;
            }
        }
        
       public static string[] threadAddressKogna =  {
            "C0080000", /*thread 0, we don't use this*/
            "C0080000", /*thread 1*/
            "C00C0000", /*thread 2*/
            "C0100000", /*thread 3*/
            "C0140000", /*thread 4*/
            "C0180000", /*thread 5*/
            "C01C0000", /*thread 6*/
            "C0200000", /*thread 7*/
        };
        
        
Calling complileKogna() with the offending C program results in the compiler error is as one would expect, but I can handle the error gracefully without terminating the process:

Code: Select all

Running Compiler: C:\KMotion5.0.6\KMotion\Release\TCC67.exe
  -args: -text C0200000 -g -nostdinc -I "C:\KMotion5.0.6\DSP_KOGNA" -I "C:\Users\GradientR9\Desktop\Kogna\KognaTemplateApp\KognaTemplateApp\Application Data\TestCfiles" -o "C:\Users\GradientR9\Desktop\Kogna\KognaTemplateApp\KognaTemplateApp\Application Data\TestCfiles\BlinkKFLOP(7).out" "C:\Users\GradientR9\Desktop\Kogna\KognaTemplateApp\KognaTemplateApp\Application Data\TestCfiles\BlinkKFLOP.c" "C:\KMotion5.0.6\DSP_KOGNA\DSPKOGNA.out"
Compiler returned with exit code: 1
Compiler Returned an eror:
C:\Users\GradientR9\Desktop\Kogna\KognaTemplateApp\KognaTemplateApp\Application Data\TestCfiles\BlinkKFLOP.c:8: 'garbargecodetest' undeclared
And running the same code with the valid KflopBlink.c program as input:

Code: Select all

Running Compiler: C:\KMotion5.0.6\KMotion\Release\TCC67.exe
  -args: -text C0200000 -g -nostdinc -I "C:\KMotion5.0.6\DSP_KOGNA" -I "C:\Users\GradientR9\Desktop\Kogna\KognaTemplateApp\KognaTemplateApp\Application Data\TestCfiles" -o "C:\Users\GradientR9\Desktop\Kogna\KognaTemplateApp\KognaTemplateApp\Application Data\TestCfiles\BlinkKFLOP(7).out" "C:\Users\GradientR9\Desktop\Kogna\KognaTemplateApp\KognaTemplateApp\Application Data\TestCfiles\BlinkKFLOP.c" "C:\KMotion5.0.6\DSP_KOGNA\DSPKOGNA.out"
Compiler returned with exit code: 0
reading code sizes from coff file: C:\Users\GradientR9\Desktop\Kogna\KognaTemplateApp\KognaTemplateApp\Application Data\TestCfiles\BlinkKFLOP(7).out
text=384 | data=16 | bss=0 | total=400
The reason that I have/use the TCC command line interface if because I primarily develop/edit Kflop C programs in VS Code and I have a helper C# app to handle the compiling during my development phases.

User avatar
TomKerekes
Posts: 2676
Joined: Mon Dec 04, 2017 1:49 am

Re: Kogna +/- 15V Enable Bit

Post by TomKerekes » Wed Apr 26, 2023 8:24 pm

Hi Jim,

I still can't reproduce it in SimpleFormsCS even using your exact garbage error.

It seems a string index is somehow going out of bounds.

When you get the exception could you look at the call stack to determine the call from the KMotion Libraries?

Thanks
Regards,

Tom Kerekes
Dynomotion, Inc.

jtremel
Posts: 39
Joined: Fri Jun 21, 2019 10:55 pm

Re: Kogna +/- 15V Enable Bit

Post by jtremel » Wed Apr 26, 2023 9:51 pm

Tom,

Your comment below got me thinking it was the length of the file path that is making the string go out of bounds.

My C file was originally at:
C:\Users\GradientR9\Desktop\Kogna\KognaTemplateApp\KognaTemplateApp\Application Data\TestCfiles\BlinkFLOP.c

When I point SimpleFormCS to compile the file above I get the crashing error.

So I moved the C file to a shorter path:
C:\KMotion5.0.6\C Programs\BlinkFLOP_ce.c

Now running SimpleFormCS and compiling the file above I get the graceful messagebox saying:
"C:\Kmotion5.0.6\C Programs\BlinkFLOP_ce.c:6: 'garbage' undeclared.

So it appears likely that the piece of code causing the crash is in the function generating the Messagebox that displays the compile errror (when the file path is above a certain length).

My guess is that you could reproduce the behavior by moving the C file to a long file path.

I don't know off-hand how to look at the call-stack within the Dynomotion dll's, but I can dig further if it will be helpful.

User avatar
TomKerekes
Posts: 2676
Joined: Mon Dec 04, 2017 1:49 am

Re: Kogna +/- 15V Enable Bit

Post by TomKerekes » Sat Apr 29, 2023 4:26 pm

Hi Jim,

You are correct. Compiler error messages were being limited to 100 characters. We have changed this to 2000 and messages will then be clipped rather than throwing an exception. We will have a new Release soon with this change and the Kogna status in the KM-MainStatus class.
Regards,

Tom Kerekes
Dynomotion, Inc.

Post Reply