AnsweredHot!Control a simulated PIC CPU with SCL

Page: < 12 Showing page 2 of 2
Author
GeorgePauley
Moderator
  • Total Posts : 832
  • 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/31 12:15:02 (permalink)
+2 (2)
Darned if I can figure out how to read from a file into a pin.  sad: sad  I have written a(nother) enhancement request.
 
However, it may be time for you to up your game a bit anyway.  The simulator is extendable.  You can write pieces of Java code and insert it into the simulator. Specifically you can design a new peripheral for the simulator.  But the "peripheral" doesn't necessarily have to do peripheral things.  (More on that later.)  As you might imagine, the capabilities of a Java extension are significantly greater than those of SCL.
 
How to do this is described in the MPLAB X SDK (http://www.opensource4pic.org/content/).  When you start reading the SDK, you'll want to jump to the sub-chapter titled:  Simulator Programmer's Guide. This section of the SDK, and the SCL User's Guide, were both written by me.  And since you're used to the SCL User's Guide, the Simulator Programmer's Guide will hopefully be pretty easy to digest.
 
The Simulator Programmer's Guide comes with 4 examples, and interestingly, one of those examples involves a "psuedo-peripheral" that injects a sine wave onto a pin!  I would imagine you would find it quite useful in your endeavors to do the same.
#21
PStechPaul
Super Member
  • Total Posts : 1313
  • Reward points : 0
  • Joined: 2006/06/27 16:11:32
  • Location: Cockeysville, MD, USA
  • Status: offline
Re: Control a simulated PIC CPU with SCL 2017/07/31 19:48:59 (permalink)
+2 (2)
It should be possible to read a text file of ADC values for register injection if the pin is an ADC. The values would need to be converted from real mV values to ADC values. I have done that fairly often, but not recently so I don't have any ready examples. I had an old project written in ASM and built with MPLAB 8.x but I tried it in MPLABX and it warned that the ADC peripheral was not implemented. This was for a PIC12F675, and the stimulus file (ADC.TXT) works using MPLAB 8.92. The contents injected into ADRESH are simply:
80
100
120
140
160
140
120
100


 
#22
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/08/01 00:44:20 (permalink)
0
Thanks for the help guys!
 
I managed to read voltage values from a .txt file and than assign them to a pin. My next task will be to create a sinus wave which will continuously be active until the system breaks because of an over voltage spike.
 
//////////////
.scl
-------------
 
if test_over_voltage_read_file == true then
      
                --MAX VOLTAGE ARE EQUAL TO 127 (127/256*5*1000 = 2481 mV )
            
                file_open(status, fileVar, "C:\workspace\cdm9\CDM9B_Summerworker_2017\cdm9b_K044161.X\data.txt", read_mode);
                
                if status == open_ok then
            
                    --if status == open_ok then
                    while endfile(fileVar) == false loop
                
                        report "=== TEST ===";
                        readline(fileVar, data_line);
                        
                        --report "WAIT FOR AD SENSOR TO RESET";
                        wait until ADCON0.GO_nDONE == '0';
                        
                        --report "SET AD VALUE";
                        read(data_line, RA0);
                        --RA0 <= temp_voltage;
                    
                        wait until ADCON0.GO_nDONE == '1';
                            --report "SAMPLING";
                        wait until ADCON0.GO_nDONE == '0';
                        
                        if ADRES < 127 then
                        
                            report "TEST BELOW MAX VALUE";
                            
                            while RA2 != '1' loop
                                wait for 200 ms;
                                report "wait for 200 ms";
                            end loop;
                                
                            if RA2 == '1' then
                                report "NO OVER VOLTAGE TEST ( OK ) | Max 2481 mV";
                            else
                                report "NO OVER VOLTAGE TEST ( ERROR )";
                            end if;
                                    
                            if F_TimeOut == 0 then
                                report "F_TimeOut = 0 ( OK ) ";
                            else
                                report "F_TimeOut = ? ( ERROR : Check Watch )";
                            end if;
                            
                        else
                        
                            report "TEST ABOVE MAX VALUE";
                                
                            while RA2 != '0' loop
                                wait for 200 ms;
                                report "wait for 200 ms";
                            end loop;
                                
                            if RA2 == '0' then
                                report "OVER VOLTAGE TEST  ( OK ) | Max 2481 mV";
                            else
                                report "OVER VOLTAGE TEST ( ERROR )";
                            end if;
                                    
                            if F_TimeOut == 1 then
                                report "F_TimeOut = 1 ( OK ) ";
                            else
                                report "F_TimeOut = ? ( ERROR : Check Watch )";
                            end if;
                            
                        end if;    
                        
                    wait for 500 us;
                        
                    end loop;
                    file_close(fileVar);
                    wait;
                    
                else
                    report "SYSTEM ERROR : Data file not found";
                end if;
                
 
        end if;
//////////////////
////////////////////
data.txt
----
2200 mV
2300 mV
2400 mV
2500 mV
2600 mV
 
////////////////
#23
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/08/01 01:03:21 (permalink)
+1 (1)
Thanks!!! I've look into that Pauley Smile: Smile My supervisor at my company wants me to create complex stimuli tests in the future. I told him that comprehensive stimuli test might be tricky in case of scenarios when we must handle several sinus waves and simulate communication between other CPUs and so on. There is also several state machines, timers and interrupts which must be talking care of. As conclusion I don't know if its possible to go much further with these SCL tests before it gets to heavy, for a couple of days ago I had to many process running at once which caused Mplab to crash.
 
Is it possible to generate a sinus waves in java and transform the signal to a mV value?
 
Again, Thank you for your prompt reply!
 
#24
GeorgePauley
Moderator
  • Total Posts : 832
  • Reward points : 0
  • Joined: 2009/12/01 13:59:30
  • Location: Chandler AZ
  • Status: offline
Re: Control a simulated PIC CPU with SCL 2017/08/01 08:20:44 (permalink)
+1 (1)
PStechPaul
It should be possible to read a text file of ADC values for register injection if the pin is an ADC. The values would need to be converted from real mV values to ADC values.


Paul, This sounds like MPLAB 8 style ADC injection.  In MPLAB 8 we didn't model the pins, so injection was straight to the ADCBUF result registers, as you said, already converted to ADC values.  But in MPLAB X we do model the pins so we typically inject a voltage directly to the pin, and let the ADC do it's conversion thing.
 
You can still do the old MPLAB 8 style injections, but you have to check a box in the ADC tab of the simulator properties.
#25
GeorgePauley
Moderator
  • Total Posts : 832
  • Reward points : 0
  • Joined: 2009/12/01 13:59:30
  • Location: Chandler AZ
  • Status: offline
Re: Control a simulated PIC CPU with SCL 2017/08/01 08:49:27 (permalink)
0
Oskar, Ah that's the trick!
 

read(data_line, RA0);

 
I was trying
 

read(file_var, voltVar);
AN0 <= voltVar;

 
Thanks.
#26
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/08/13 23:06:33 (permalink)
0
George, another unrelated issue. Is it possible to import makefiles into Mplab? At the moment I'm running some CUnit tests on Cygwin but my supervisor want to move them to Mplab.
 
Thanks,
//Oskar
#27
GeorgePauley
Moderator
  • Total Posts : 832
  • Reward points : 0
  • Joined: 2009/12/01 13:59:30
  • Location: Chandler AZ
  • Status: offline
Re: Control a simulated PIC CPU with SCL 2017/08/14 11:45:03 (permalink)
+1 (1)
oscdah94
George, another unrelated issue. Is it possible to import makefiles into Mplab? At the moment I'm running some CUnit tests on Cygwin but my supervisor want to move them to Mplab.

 
I doubt it.  But this is way outside my area of expertise.  I would ask this question in the MPLAB X IDE forum.
#28
Page: < 12 Showing page 2 of 2
Jump to:
© 2017 APG vNext Commercial Version 4.5