VCL语法教程——4.map的使用
-
map类似于pspice里面的建模,输入一个X对应一个Y。通过点的数量,来绘制出曲线,在通过给定一个值X,带入曲线得到对应的输出Y。
-
如何定义一个map,
例,定义一个名叫map1的图标,通过5个点进行绘制。图形见:
实现代码如下:
第一个参数是map的命名,
第二个参数是map点的数量,
后面5对数据对应5个点的X,Y。这里默认最大的I16就是100%,所以100%对应32767,80%就是26214,40%就是13107
setup_map(map1,5, 0,32767, 14746,32767, 19660,26214, 26214,13107)
-
map的使用
map使用采用接口函数get_map_output( mapname,X_value)
第一个参数就是调用的map的名字
第二个参数就是输入的X值
例,调用map1,输入temp1得到对应的Y值temp2
temp2=get_map_output(map1,temp1)
- 配套api,值的缩放。
1.自动缩放,4ms一次,缩放的值保存在SCL#_output
automate_scale(SCL#,Input,SF)
参数定义:1.SCL#, 选择缩放模块,SCL1~SCL4
2.Input,输入值
3.SF,缩放因子,是一个I16的值,如果想缩放50%就设定为16383。如果不缩放就是100%,32767.
2.手动缩放,返回缩放以后的值scale_value(SCL#,Input)
temp1 equals user12
temp1=scale_value(SCL1,temp1)
3.设置SCL#通道的缩放因子
setup_scale_factor(SCL#,SF)
- 自动功能,类似于DMA功能,自动绑定好后就可以自行处理。
例,
1. 从POT2自动得到数据代入到MAP1中,得到缩放比例MAP1_OUTPUT
2. 将POT1的数据通过MAP1_OUTPUT的缩放因子使用SCL3进行缩放,并且自动保存在SCL3_output。
3. 将得到的SCL3_output的值通过DAC输出。
setup_pot(POT1, THREE_WIRE)
setup_pot(POT2, THREE_WIRE)
setup_map(MAP1, 5, ; Number of points used
0, 32767, ; X = 0% Y = +100%
14746, 32767, ; X = 45% Y = +100%
19660, 26214, ; X = 60% Y = +80%
26214, 13107, ; X = 80% Y = +40%
32767, 13107, ; X =100% Y = +40%
0, 0, ;(point pair not used)
0, 0) ;(point pair not used)
automate_map(MAP1,POT2_output)
automate_scale(SCL3,POT1_output,MAP1_output)
automate_dac(DAC1,SCL3_output,1,0)
while (1=1) {}