在SCL Code Repo 和 MPLAB IDE 帮助中提供的 SCL 用户指南中进行了一些研究,并进行了一些测试后,即使使用直接的 SCL 代码,我也无法从文件中获取值。我首先使用的 SCL 代码如下:
configuration for "pic18f458" is
end configuration;
testbench for "pic18f458" is
begin
// Register Injection
process is
file fileVar : text;
variable status : file_open_status;
variable val : integer;
begin
report("Analog injection started...");
file_open(status, fileVar, "<file_path>", read_mode);
if status == open_ok then
report("Reading the values file...");
while endfile(fileVar) == false loop
read(fileVar, val);
wait until ADCON0.GO_nDONE == '1';
report("Conversion started");
wait until ADCON0.GO_nDONE == '0';
report("Conversion ended");
if ADCON1.ADFM == '0' then -- left justified
ADRESH <= val / 4;
ADRESL <= val * 64;
else -- right justified
ADRESH <= val / 256;
ADRESL <= val;
end if;
end loop;
file_close(fileVar);
wait;
end if;
end process;
end testbench;
我确实在模拟器输出中看到了报告字符串,但是 ADRES 寄存器总是被注入0xFFFF价值。我尝试修改版本但没有成功。
然而,当我决定修改 SCL 代码并尝试使用代码内变量时,它确实起作用了。代码内变量的值已正确注入。从这个案例中我发现文件读取操作在某处失败并且无法正确地从文件中获取值。后者的工作 SCL 代码如下:
configuration for "pic18f458" is
end configuration;
testbench for "pic18f458" is
begin
// Register Injection
process is
file fileVar : text;
variable status : file_open_status;
variable val : integer;
begin
report("Analog injection started...");
val := 7;
while val < 1024 loop
wait until ADCON0.GO_nDONE == '1';
report("Conversion started");
wait until ADCON0.GO_nDONE == '0';
report("Conversion ended");
if ADCON1.ADFM == '0' then -- left justified
ADRESH <= val / 4;
ADRESL <= val * 64;
else -- right justified
ADRESH <= val / 256;
ADRESL <= val;
end if;
val := val * 8;
end loop;
report("Analog injection ended...");
wait;
end process;
end testbench;
上述 SCL 代码将在每次 ADC 转换结束时注入 val 变量的实际值(GO_nDONE 位首先变为高电平,当转换完成时变为低电平)。根据ADFM位进行值注入。如果设置为 0,则值将左对齐,否则将右对齐。
所以我在微芯片论坛上发了an issue关于这个问题。让我们看看它将如何解决。
好吧,如果这些值不需要非常具体,您可以使用第二个 SCL 代码。但是,为了在 MPLABX IDE 中启用寄存器注入,您需要先配置模拟器。去做这个
- 通过单击打开项目属性窗口文件 -> 项目属性在菜单中。
- 然后从类别部分选择模拟器.
- 选择外设:ADC1来自选项类别在右窗格中。
- 最后确保为 ADCxBUF0 使用 MPLAB 8 样式激励/SCL如下图所示。
配置好后打开刺激窗口,首先启动模拟一次,以便显示其内容,然后单击附加 SCL 文件图标附加您的 SCL 文件,最后使用新附加的 SCL 重新启动仿真。