NI-6221 pwm相关函数

一、PWM的配置

1.DAQmxCreateCOPulseChanFreq (我用这个)

1)用途

创建通道以生成频率和工作周期定义的数字脉冲,并将通道添加到使用taskHandle指定的任务中。除非您选择不同的输出端子,否则脉冲会出现在计数器的默认输出端子上。

2)参数

NameTypeDescription
taskHandleTaskHandleThe task to which to add the channels that this function creates.
counterconst char []The name of the counter to use to create virtual channels. You can specify a list or range of physical channels.
nameToAssignToChannelconst char []The name(s) to assign to the created virtual channel(s). If you do not specify a name, NI-DAQmx uses the physical channel name as the virtual channel name. If you specify your own names for nameToAssignToChannel, you must use the names when you refer to these channels in other NI-DAQmx functions.

If you create multiple virtual channels with one call to this function, you can specify a list of names separated by commas. If you provide fewer names than the number of virtual channels you create, NI-DAQmx automatically assigns names to the virtual channels.
unitsint32The units in which to specify freq.
Name Description
DAQmx_Val_Hz hertz
idleStateint32The resting state of the output terminal.
Value Description
DAQmx_Val_High High state.
DAQmx_Val_Low Low state.
initialDelayfloat64The amount of time in seconds to wait before generating the first pulse.
freqfloat64The frequency at which to generate pulses.
dutyCyclefloat64The width of the pulse divided by the pulse period. NI-DAQmx uses this ratio, combined with frequency, to determine pulse width and the interval between pulses.

2.DAQmxCreateCOPulseChanTicks

1)用途:创建通道以生成由脉冲处于高状态的时基计时信号数和脉冲处于低状态的时基计时信号数定义的数字脉冲,并将通道添加到使用taskHandle指定的任务中。除非您选择不同的输出端子,否则脉冲会出现在计数器的默认输出端子上。

2)参数:

NameTypeDescription
taskHandleTaskHandleThe task to which to add the channels that this function creates.
counterconst char []The name of the counter to use to create virtual channels. You can specify a list or range of physical channels.
nameToAssignToChannelconst char []The name(s) to assign to the created virtual channel(s). If you do not specify a name, NI-DAQmx uses the physical channel name as the virtual channel name. If you specify your own names for nameToAssignToChannel, you must use the names when you refer to these channels in other NI-DAQmx functions.

If you create multiple virtual channels with one call to this function, you can specify a list of names separated by commas. If you provide fewer names than the number of virtual channels you create, NI-DAQmx automatically assigns names to the virtual channels.
sourceTerminalconst char []The terminal to which you connect an external timebase. You also can specify a source terminal by using a terminal name.
idleStateint32The resting state of the output terminal.
Value Description
DAQmx_Val_High High state.
DAQmx_Val_Low Low state.
initialDelayint32The number of timebase ticks to wait before generating the first pulse.
lowTicksint32The number of timebase ticks that the pulse is low.
highTicksint32The number of timebase ticks that the pulse is high.

3.DAQmxCreateCOPulseChanTime

1)用途:创建通道以生成由脉冲处于高状态的时间量和脉冲处于低状态的时间量定义的数字脉冲,并将通道添加到使用taskHandle指定的任务中。除非您选择不同的输出端子,否则脉冲会出现在计数器的默认输出端子上。

2)参数

taskHandleTaskHandleThe task to which to add the channels that this function creates.
counterconst char []The name of the counter to use to create virtual channels. You can specify a list or range of physical channels.
nameToAssignToChannelconst char []The name(s) to assign to the created virtual channel(s). If you do not specify a name, NI-DAQmx uses the physical channel name as the virtual channel name. If you specify your own names for nameToAssignToChannel, you must use the names when you refer to these channels in other NI-DAQmx functions.

If you create multiple virtual channels with one call to this function, you can specify a list of names separated by commas. If you provide fewer names than the number of virtual channels you create, NI-DAQmx automatically assigns names to the virtual channels.
unitsint32The units in which to define pulse high and low time.
Value Description
DAQmx_Val_Seconds Seconds
idleStateint32The resting state of the output terminal.
Value Description
DAQmx_Val_High High state.
DAQmx_Val_Low Low state.
initialDelayfloat64The amount of time in seconds to wait before generating the first pulse.
lowTimefloat64The amount of time the pulse is low, in seconds.
highTimefloat64

The amount of time the pulse is high, in seconds.

二、控制PWM脉冲产生的个数

1.DAQmxCfgImplicitTiming

1)用途:仅设置要获取或生成的样本数,而不指定计时。通常,当任务不需要采样计时时,应使用此函数,例如使用计数器进行缓冲频率测量、缓冲周期测量或脉冲序列生成的任务。对于有限的计数器输出任务,sampsPerChanToAcquire是要生成的脉冲数。

2)参数

taskHandleTaskHandleThe task used in this function.
sampleModeint32Specifies whether the task acquires or generates samples continuously or if it acquires or generates a finite number of samples.
Value Description
DAQmx_Val_FiniteSamps Acquire or generate a finite number of samples.
DAQmx_Val_ContSamps Acquire or generate samples until you stop the task.
DAQmx_Val_HWTimedSinglePoint Acquire or generate samples continuously using hardware timing without a buffer. Hardware timed single point sample mode is supported only for the sample clock and change detection timing types.
sampsPerChanToAcquireuInt64The number of samples to acquire or generate for each channel in the task if sampleMode is DAQmx_Val_FiniteSamps. If sampleMode is DAQmx_Val_ContSamps, NI-DAQmx uses this value to determine the buffer size.

三、控制PWM频率

1.DAQmxWriteCtrFreq

1)用途:在包含一个或多个通道的连续计数器输出任务中,向每个通道写入新的脉冲频率和占空比。

2)参数

taskHandleTaskHandleThe task to write samples to.
numSampsPerChanint32The number of samples, per channel, to write. You must pass in a value of 0 or more in order for the sample to write. If you pass a negative number, this function returns an error.
autoStartbool32Specifies whether or not this function automatically starts the task if you do not start it.
timeoutfloat64The amount of time, in seconds, to wait for this function to write all the samples. To specify an infinite wait, pass -1 (DAQmx_Val_WaitInfinitely). This function returns an error if the timeout elapses.

A value of 0 indicates to try once to write the submitted samples. If this function successfully writes all submitted samples, it does not return an error. Otherwise, the function returns a timeout error and returns the number of samples actually written.
dataLayoutbool32Specifies how the samples are arranged, either interleaved or noninterleaved.
Value Description
DAQmx_Val_GroupByChannel Group by channel (noninterleaved)
DAQmx_Val_GroupByScanNumber Group by sample (interleaved)
frequencyfloat64 []Specifies at what frequency to generate pulses.
dutyCyclefloat64 []The width of the pulse divided by the pulse period. NI-DAQmx uses this ratio, combined with frequency, to determine both pulse width and pulse delay.
reservedbool32 *Reserved for future use. Pass NULL to this parameter.

 

 

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

孙八瓶

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值