AnsweredHot!Control a simulated PIC CPU with SCL

Page: 12 > Showing page 1 of 2
Author
oscdah94
New Member
  • Total Posts : 16
  • Reward points : 0
  • Joined: 2017/07/05 02:22:58
  • Location: 0
  • Status: offline
2017/07/08 16:12:40 (permalink)
0

Control a simulated PIC CPU with SCL

Hi everybody,
 
I’m for the moment scripting some stimuli tests in SCL. Because of the non-documentation, I than wonder if there is an another way to stop the CPU in the simulator with the help of SCL? An example might be to HALT CPU and then start it again from a reference point in the code. The purpose is to create a state machine which tests specific source code.  The machine are at the moment running on wait commands which are not working that good, due because of the timing.
 
 Please, also give tips due I’m a rookie SCL scripter.
 
 
 
Thanks all
Oskar
#1
GeorgePauley
Moderator
  • Total Posts : 860
  • Reward points : 0
  • Joined: 2009/12/01 13:59:30
  • Location: Chandler AZ
  • Status: offline
Re: Control a simulated PIC CPU with SCL 2017/07/10 09:00:57 (permalink) ☼ Best Answerby oscdah94 2017/07/12 00:51:53
+1 (1)
SCL is documented.  Go to your MPLAB X installation directory and then
 
     ..\docs\SCL_Users_Guide\index.html
 
AFTER you work through the tutorial in the SCL User's Guide, take a look at this project from my MASTERS simulator class.  It shows how to handshake between the simulator and SCL to keep them in lock step with each other.
#2
oscdah94
New Member
  • Total Posts : 16
  • Reward points : 0
  • Joined: 2017/07/05 02:22:58
  • Location: 0
  • Status: offline
Re: Control a simulated PIC CPU with SCL 2017/07/12 01:41:56 (permalink)
0
Thanks for the material!
 
I analyzed your SCL script and I see that you are using "wait until PC reached main", to make sure that the script are timed with your code.  This solution doesn't solve my problem. From my point of view I want to completely stop the simulator from an executed command in the SCL script, the purpose is to stop the simulation and set an amount of pins, which will interact with a source code. Furthermore, another command should than start the simulation at the "former stop point". I've been looking around all over the internet to find a command with that such of expertise.
 
I found that MDB are using similar commands ( http://microchipdeveloper.com/mplabx:mdb )  like halt, continue and so forth. Though it's very sad that these commands are not compatible with SCL.
 
 
 
 
I want to be able to do something like this pseudocode below.
  process is
        begin
            halt Simulation
            RC7 <= ‘1’;
            RA4 <= ‘1’;
            continue Simulation
end process;
 
thanks/
Oskar
#3
GeorgePauley
Moderator
  • Total Posts : 860
  • Reward points : 0
  • Joined: 2009/12/01 13:59:30
  • Location: Chandler AZ
  • Status: offline
Re: Control a simulated PIC CPU with SCL 2017/07/12 14:20:04 (permalink)
+1 (1)
Let's see if we can dispel some misconceptions here.  mr green: mr green
 
Within MPLAB (and MDB) there is a component called the Debugger, which handles operations like run, step, halt, breakpoints, etc.  The Debugger controls tools like Real ICE, ICD and simulator, telling them when to run, step, halt, etc.  Within the simulator is a special component called SCL that is responsible for injecting values into the simulator (e.g. setting pins) while the simulator is running. 
 
     Debugger    ->     Simulator     ->    SCL
     (run, etc)          (instructions)          (injections)
 
The point I'm trying to make is that SCL is 2 levels down from the component that handles halting.  SCL isn't intended to halt a tool.
 
But you can still do what you want to do, just not the way you are currently trying to do it.
 
Let's start with the idea that you can load an SCL file any time you want.  So you could
 
     1.  Set a breakpoint
     2.  Run until you hit the breakpoint
     3.  Attach your SCL file that sets your pins etc.
     4.  Continue running
 
Next, it is perfectly fine to have multiple SCL files that get loaded at different times and doing different things.
 
Finally you can attach SCL files in MDB via the "stim" command.  MDB is also documented so you can learn about how to use the "stim" command.  You'll find the MDB document, again, in the docs sub folder of your MPLAB X installation.
 
So your MDB script might look something like
 
     b line#1
     run
     wait
     stim "myfile.scl"
     run
     wait
 
post edited by GeorgePauley - 2017/07/12 14:23:50
#4
oscdah94
New Member
  • Total Posts : 16
  • Reward points : 0
  • Joined: 2017/07/05 02:22:58
  • Location: 0
  • Status: offline
Re: Control a simulated PIC CPU with SCL 2017/07/13 05:12:53 (permalink)
0
Thanks for the idea, I'll look into that!
 
Another question. I'm at the moment developing a state machine in the SCL script, which are built on wait until a pin changes state (wait until RC6 == '1'; ). The problem is that the pin are always 1, and still is the wait condition staying in that position forever. I've tried to created an extra process which print out the value of RC6 = 1/0.
The print tells me that RC6 are always equal to 1, but yet is the script waiting in that condition forever.
 
I don't know if this is a common bug, but it seems really strange to me.
 
Both RC5 and RC6 turn 1 and still just RC5 pass.
 
report "IO71";
        //IO71 -- Begin
      
            //I
            RC3 <= '1';
            RC4 <= '1';
        
            //O
            wait until RC5 == '1';
            report "OK";
            wait until RC6 == '1'; <--- Don't work!!!!!!!!!!!!!!!!!!!!!!!!
            report "OK";
      
            //7
            RC3 <= '0';
            RC4 <= '0';
            
            //1
            wait until RC5 == '0';
            report "OK";
            wait until RC6 == '0';
            report "OK";
            
        //IO71 -- end
 
Thanks again/
Oskar
#5
GeorgePauley
Moderator
  • Total Posts : 860
  • Reward points : 0
  • Joined: 2009/12/01 13:59:30
  • Location: Chandler AZ
  • Status: offline
Re: Control a simulated PIC CPU with SCL 2017/07/13 09:19:26 (permalink)
+2 (2)
All these years and no one has noticed this before?!  sad: sad
 
To be fair, it took me a bit to figure out what was going on.  The executive summary is that your SCL code won't work if RC5 and RC6 both become '1' simultaneously.  (Or if they are already both '1' when the SCL code is ran.)  If RC5 goes high on one cycle and then subsequently RC6 goes high on a later cycle your SCL code will work.
 
This is, of course, a bug in SCL.  But hopefully you have enough information to work around until we can get this fixed?
#6
oscdah94
New Member
  • Total Posts : 16
  • Reward points : 0
  • Joined: 2017/07/05 02:22:58
  • Location: 0
  • Status: offline
Re: Control a simulated PIC CPU with SCL 2017/07/14 04:09:09 (permalink)
0
Thanks for your immense knowledge!
 
No problem with that issue, I'll just enter break points in my code and validate if RC6 are correct by looking in the mplab watch. Good luck fixing it! Any time guess?
 
Again, another question Smile: Smile
I went over from a single process script to multi a process script. However, are there any way to declare shared variables between two processes? Couldn't find any kind of information about declaring shared variables in SCL. I know there are possibilities to declare variables in the source code and than share them into my SCL script, the problem is that i don't want to influence my source code.
 
Full code is visualized below.
 
configuration for "pic16f76" is
end configuration;

testbench for "pic16f76" is
    variable send_bit_0_flag : boolean := false; //<--------------I know this won't work
    variable send_bit_1_flag : boolean := false; //<--------------I know this won't work
begin

    send_bit_0: process is
        begin
        
        wait for 1 us;
        
        if send_bit_0_flag then
        
            report "Try to send 9;31";
            //9;31 -- begin
            
                //9
                report "Send to B from A : 9";
                RC3 <= '0';
                RC4 <= '1';
            
                //;
                report "Send to B from A : ;";
                wait until RC6 == '1';
                
                //3
                report "Send to B from A : 3";
                RC3 <= '0';
                RC4 <= '0';
            
                //1
                report "Send to B from A : 1";
                wait until RC6 == '0';
            
            //9;31 -- end
            
            send_bit_0_flag := false;
        end if;
    
    end process send_bit_0;

    send_bit_1: process is
        begin
        
        wait for 1 us;
        
        if send_bit_1_flag then
        
            report "Try to send IKCA";
            //IKCA -- begin
            
                //I
                report "Send to B from A : I";
                RC3 <= '1';
                RC4 <= '1';
            
                //K
                report "Wait for resonse from B to A : K";
                wait until RC6 == '1';
                report "Wait OK";
                
                //C
                report "Send to B from A : C";
                RC3 <= '1';
                RC4 <= '0';
            
                //A
                report "Wait for resonse from B to A : A";
                wait until RC6 == '0';
                report "Wait OK";
            
            //IKCA -- end
            
            send_bit_1_flag := false;
        end if;
    
    end process send_bit_1;

    

    main_process: process is
        begin
        
        wait for 1 us;
        
        //Send 01110000
        send_bit_0_flag := true;
        send_bit_1_flag := true
        send_bit_1_flag := true
        send_bit_1_flag := true
        send_bit_0_flag := true;
        send_bit_0_flag := true;
        send_bit_0_flag := true;
        send_bit_0_flag := true;
      
    end process main_process;
end testbench;
 
 
Thanks/
Oskar
#7
GeorgePauley
Moderator
  • Total Posts : 860
  • Reward points : 0
  • Joined: 2009/12/01 13:59:30
  • Location: Chandler AZ
  • Status: offline
Re: Control a simulated PIC CPU with SCL 2017/07/14 09:59:11 (permalink)
+3 (3)
oscdah94
Good luck fixing it! Any time guess?

 
The problem is proving to be difficult, as is usually the case with SCL, which is some of the most complex code in the simulator.  But I would think by MPLAB X 4.05.  (MPLAB X 4.0 is already in code-freeze.)
 
oscdah94
I went over from a single process script to multi a process script. However, are there any way to declare shared variables between two processes? Couldn't find any kind of information about declaring shared variables in SCL. I know there are possibilities to declare variables in the source code and than share them into my SCL script, the problem is that i don't want to influence my source code.



No there is no way to share SCL variables between processes at this time.  I will add this to my infinitely long list of simulator improvements to implement before I retire.  wink: wink
 
But I think you are on the right track with your idea of using variables from your application source code.  If you have an extra word or two in general purpose RAM you can declare a variable or two in your application.  You can do all the setting and testing of the variables from within your SCL code.  So the only influence on your source code is that you are using an extra word or two of RAM.
post edited by GeorgePauley - 2017/07/14 10:52:13
#8
oscdah94
New Member
  • Total Posts : 16
  • Reward points : 0
  • Joined: 2017/07/05 02:22:58
  • Location: 0
  • Status: offline
Re: Control a simulated PIC CPU with SCL 2017/07/17 00:10:38 (permalink)
0
haha,  I understand. grin: grin
 
I appreciate the help for answering all my questions. My questions are over at the moment but I probably have some more in the future.
 
best regards/
Oskar
#9
oscdah94
New Member
  • Total Posts : 16
  • Reward points : 0
  • Joined: 2017/07/05 02:22:58
  • Location: 0
  • Status: offline
Re: Control a simulated PIC CPU with SCL 2017/07/17 05:25:35 (permalink)
0
Of course I ran in to some more problems regrading these shared variables.
 
I've declared one variable in my c code which i than imported as a "shared variable (shared variable send_bits;)" in my SCL script. However, my SCL script seems to by non-assignable for shared variables, though I've tried both static and extern variables in my c code.
 
I reduced the code but in the end I want to do something like this code snippet below.
 
--C Code
//test 1
.h
extern volatile int send_bits;
.c
volatile int send_bits;
//test 2
volatile static int send_bits;
 
--SCL
//Tested for both test 1 & test 2
 
configuration for "pic16f76" is
    shared variable send_bits;
end configuration;
 
testbench for "pic16f76" is
begin
 
 
 report_process: process is
        begin
            wait for 1 ms;
   if send_bits == 1 then
        report "1";
   end if;
      
end process report_process;
 
 
 main_process: process is
        begin
    wait for 1 ms;
        send_bits := 1;
end process main_process;
end testbench;
 
I don't understand why this shouldn't work. Hopefully you maybe know. grin: grin
 
best regards/
Oskar
#10
GeorgePauley
Moderator
  • Total Posts : 860
  • Reward points : 0
  • Joined: 2009/12/01 13:59:30
  • Location: Chandler AZ
  • Status: offline
Re: Control a simulated PIC CPU with SCL 2017/07/17 09:22:23 (permalink)
+2 (2)
Unfortunately SCL isn't smart enough to handle scoping on variables.  Make the variable global and SCL should see it.
#11
GeorgePauley
Moderator
  • Total Posts : 860
  • Reward points : 0
  • Joined: 2009/12/01 13:59:30
  • Location: Chandler AZ
  • Status: offline
Re: Control a simulated PIC CPU with SCL 2017/07/19 13:33:09 (permalink)
+2 (2)
conditional wait statement has been corrected.  You should see the fix in MPLAB X 4.05.
#12
oscdah94
New Member
  • Total Posts : 16
  • Reward points : 0
  • Joined: 2017/07/05 02:22:58
  • Location: 0
  • Status: offline
Re: Control a simulated PIC CPU with SCL 2017/07/20 02:20:33 (permalink)
0
Thanks for the quick fix! grin: grin
 
Another question wink: wink
 
Is it possible to mask a bit from a variable??
 
#define PING_ERROR_1          2048; //(binary)
extern bank2 unsigned int      F_TimeOut_Error;
 
if PING_ERROR == PING_ERROR & F_TimeOut_Error then
         report "PING ERROR";
else
        report "NO PING ERROR";
end if;
 
best regards
//Oskar
 
#13
GeorgePauley
Moderator
  • Total Posts : 860
  • Reward points : 0
  • Joined: 2009/12/01 13:59:30
  • Location: Chandler AZ
  • Status: offline
Re: Control a simulated PIC CPU with SCL 2017/07/20 09:47:19 (permalink)
+2 (2)
Boolean operators have not been implemented yet.  There is an existing enhancement request to do so.  But the lack of the Boolean operators hasn't been a serious hindrance to customers so we haven't gotten around to it yet. 
#14
GeorgePauley
Moderator
  • Total Posts : 860
  • Reward points : 0
  • Joined: 2009/12/01 13:59:30
  • Location: Chandler AZ
  • Status: offline
Re: Control a simulated PIC CPU with SCL 2017/07/24 11:52:04 (permalink)
+2 (2)
GeorgePauley
conditional wait statement has been corrected.  You should see the fix in MPLAB X 4.05.

 
Sigh.  Now I'm pulling this back out.  Here's the issue.  You were attempting to do this
 

     wait until RC6 == '1';

 
But it didn't work because when this SCL line was executed RC6 was already equal to 1.  The generated SCL "byte code" would wait until RC6 had changed value before checking the condition.  So I changed the way SCL worked to check the condition before entering the wait state. 
 
This seemed like a good idea.  But then we tripped over this
 

     process is
          begin
          wait until RC6 == '1';
          report("RC6 was seen to be '1'");
          end process;

 
The moment RC6 becomes 1, this SCL process is infinite.  So we would have to modify the code as follows.
 

     process is
          begin
          wait until RC6 == '1';
          report("RC6 was seen to be '1'");
          wait until RC6 != '1';
          end process;

 
So now we realize that this change likely breaks quite a bit of existing SCL code.  (Including many of our own automated tests!)  So, I'm going to revert the SCL code to work the way it used to (ie, wait for value change then check value).  No sense breaking all the existing code.
 
If it is possible that your condition could be true before entering the wait statement you need to do this.
 

     if (RC6 != '1') then
          wait until RC6 == '1';
     end if;

 
Which is no less cumbersome than waiting for RC6 != '1' in the previous example.  But it doesn't pull the rug out from under the existing SCL users. 
 
Sorry for the confusion.
#15
oscdah94
New Member
  • Total Posts : 16
  • Reward points : 0
  • Joined: 2017/07/05 02:22:58
  • Location: 0
  • Status: offline
Re: Control a simulated PIC CPU with SCL 2017/07/27 01:03:15 (permalink)
0
Thanks for the great update, I appreciate it grin: grin
 
Otherwise, regarding the topic about boolean operators. My idea was whether SCL supports bit masking operations, not boolean operators.
I want to mask a bit from an error flag, and than validate if the correct error occurred in my SCL script. The different flags are assigned as a binary value (bits) in one variable (error flag).
 
                        FLAG 0010 0001
                        MASK 0000 0001
                        AND---------------
       MASKED ERROR   0000 0001
 
Sorry for my later answer.
 
//Oskar
#16
oscdah94
New Member
  • Total Posts : 16
  • Reward points : 0
  • Joined: 2017/07/05 02:22:58
  • Location: 0
  • Status: offline
Re: Control a simulated PIC CPU with SCL 2017/07/27 02:06:24 (permalink)
0
Another question. Can you possible find any errors in this code?
I'm not enable to attach it to Mplab.
 
ERROR : E0101-SIM: Failed to dissemble instruction (line 1824)
------------------------
test_file.scl
 
if test_over_voltage_read_file == true then
        
            report "=========================================== -- BEGIN";
            report " OVER VOLTAGE TEST : READ FILE"
            report " 17-07-27 ";
            report "===========================================";
                
                --MAX VOLTAGE ARE EQUAL TO 127 127/256*5*1000 = 2481
                variable fileVar : file;
                variable status  : file_open_status;
            
                file_open(status, fileVar, "C:\workspace\cdm9\CDM9B_Summerworker_2017\cdm9b_K044161.X\data.txt", read_mode);
                
                if status == open_ok then
                    while endfile(fileVar) == false loop
                        
                        read(fileVar, RA0);
                        
                        if RA0 < 2481 then
                        
                            if RA2 == '1' then
                                report "NO OVER VOLTAGE TEST IS ( OK ) | Max 2481 mV : Test value 2241 mV";
                            else
                                report "NO OVER VOLTAGE TEST IS ( ERROR )";
                            end if;
                            
                            if F_TimeOut == 0 then
                                report "F_TimeOut = 0 ( OK ) ";
                            else
                                report "F_TimeOut = ? ( ERROR : Check Watch )";
                            end if;
                            
                        else
                        
                            if RA2 == '0' then
                                report "OVER VOLTAGE TEST IS ( OK ) | Max 2481 mV : Test value 2734 mV";
                            else
                                report "OVER VOLTAGE TEST IS ( ERROR )";
                            end if;
                            
                            if F_TimeOut == 1 then
                                report "F_TimeOut = 1 ( OK ) ";
                            else
                                report "F_TimeOut = ? ( ERROR : Check Watch )";
                            end if;
                        
                        end if;
                        
                    end loop;
                    file_close(fileVar);
                    wait;
                end if;
    
        end if;

        report "=========================================== -- END";
 
data.txt
 
2200 mV 2300 mV 2400 mV 2500 mV 2600 mV 2700 mV
 
#17
GeorgePauley
Moderator
  • Total Posts : 860
  • Reward points : 0
  • Joined: 2009/12/01 13:59:30
  • Location: Chandler AZ
  • Status: offline
Re: Control a simulated PIC CPU with SCL 2017/07/27 09:47:49 (permalink)
0
oscdah94
Otherwise, regarding the topic about boolean operators. My idea was whether SCL supports bit masking operations, not boolean operators.
I want to mask a bit from an error flag, and than validate if the correct error occurred in my SCL script. The different flags are assigned as a binary value (bits) in one variable (error flag).

 
Boolean and logical operators not implemented yet.  There is a long standing enhancement request for these features, which has moved fairly high up on my infinitely long list of things to do for the simulator.  But not quite as high as integrating formal Atmel devices into MPLAB X.  mr green: mr green
 
#18
GeorgePauley
Moderator
  • Total Posts : 860
  • Reward points : 0
  • Joined: 2009/12/01 13:59:30
  • Location: Chandler AZ
  • Status: offline
Re: Control a simulated PIC CPU with SCL 2017/07/27 09:52:17 (permalink)
+1 (1)
oscdah94
Another question. Can you possible find any errors in this code?
I'm not enable to attach it to Mplab.
 
ERROR : E0101-SIM: Failed to dissemble instruction (line 1824)

 
Wow, you have (at least) 1824 lines in your SCL source?!  Which one of the snippets of SCL code you gave is line #1824?
#19
oscdah94
New Member
  • Total Posts : 16
  • Reward points : 0
  • Joined: 2017/07/05 02:22:58
  • Location: 0
  • Status: offline
Re: Control a simulated PIC CPU with SCL 2017/07/31 00:10:40 (permalink)
+1 (1)
I found the error, I was declaring a "variable" variable instead as "file" variable.
 
Btw, I'm trying to generate a sinus wave to a pin on the CPU. I've tried to read from a file using the SCL script, but the problem is that I don't know how to solve it. The input format should be represented as a "mV" value.
However, the task is to simulate an electric input the to AD-C and than analyze if there if there might be any case of  over voltage.
 
To the question, is there any way to read "mV" values and than assign them to an input pin?
 
best regards
Oskar
#20
Page: 12 > Showing page 1 of 2
Jump to:
© 2017 APG vNext Commercial Version 4.5