0

This is a continuation of the question posed in How do you run a SCL file in MPLAB without a "Run SCL" button

I have an assembly code for PIC18F458 that gets data from channel 0 (RA0) of ADC and displays the result on PORTC and PORTD.

Although, I have managed to verify that the code operates as desired within Proteus, I am struggling to do the same within the MPLAB X simulator environment using a SCL file, and I suspect that this is due to the way that the text files, referred to by it, are laid out. (Please see below)

testbench for "pic18f458" is
begin
    process is
        file    datafile   : text;
        variable intVar     : integer;
        variable sampling_voltage : integer;
        variable fileStatus : file_open_status;
        variable fileLine   : line;         
        begin
            loop
                report("Analog injection started...");   
                file_open(fileStatus, datafile, "text2.txt", read_mode);
                if fileStatus == open_ok then 
                    report("Reading the values file...");   
                    while endfile(datafile) == false loop 
                        wait until ADCON0.GO_nDONE == '1';
                        report("Conversion started");
                        readline(datafile, fileLine);
                        wait for 400 ns;
                        read(fileLine, intVar);
                        sampling_voltage := intVar; -- sample input voltage
                        wait until ADCON0.GO_nDONE == '0';
                        report("Conversion ended"); 
                        if ADCON1.ADFM == '0' then  -- left justified
                            ADRESH <= sampling_voltage / 4;
                            ADRESL <= sampling_voltage * 64;
                        else                        -- right justified
                            ADRESH <= sampling_voltage / 256;
                            ADRESL <= sampling_voltage;
                        end if;
                    end loop;
                file_close(datafile);
                end if;
            end loop;
        wait;
    end process;
end testbench;

The SCL file refers to 1 of 2 text files during my debugging session (text.txt and text2.txt) laid out differently. The first consists of decimal numbers from 0 to 255 and the second consists of decimal numbers representing voltages in mV.

txt.txt
    128
    192
    238
    255
    238
    192
    128
    64
    17
    0
    17
    64
    128

text2.txt
    250 mV
    500 mV
    750 mV
    1000 mV
    1250 mV
    1500 mV
    1750 mv
    2000 mV
    2250 mv
    2500 mv
    2750 mv
    3000 mv
    3250 mV
    3500 mV
    3750 mV
    4000 mV
    4250 mV
    4500 mV
    4750 mv
    5000 mV

In both cases, the ADC seems to just be churning out the numbers that it is receiving, instead of converting them. (Please see images below)

This is obviously no good, as I am getting values within the ADRES register that are greater than 10-bits, in particularly, with regards to my text2.txt values.

ADC Results with text.txt

ADC Results with text.txt

ADC Results with text2.txt

ADC Results with text2.txt

Therefore, my question is how do I correctly debug my A/D convertor code in MPLAB X v5.05 simulator using a SCL file or any other methods?

aLoHa
  • 165
  • 7
  • 1
    Have you tried the simulation with **Use MPLAB 8 Style Stimulus/SCL for ADCxBUF0** unchecked? If not, uncheck this option in order to be able to simulate with milivolt values. – Kozmotronik Feb 22 '23 at 14:46

0 Answers0