一、PWM的配置
1.DAQmxCreateCOPulseChanFreq (我用这个)
1)用途
创建通道以生成频率和工作周期定义的数字脉冲,并将通道添加到使用taskHandle指定的任务中。除非您选择不同的输出端子,否则脉冲会出现在计数器的默认输出端子上。
2)参数
Name | Type | Description | |||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
taskHandle | TaskHandle | The task to which to add the channels that this function creates. | |||||||||
counter | const char [] | The name of the counter to use to create virtual channels. You can specify a list or range of physical channels. | |||||||||
nameToAssignToChannel | const 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. | |||||||||
units | int32 | The units in which to specify freq.
| |||||||||
idleState | int32 | The resting state of the output terminal.
| |||||||||
initialDelay | float64 | The amount of time in seconds to wait before generating the first pulse. | |||||||||
freq | float64 | The frequency at which to generate pulses. | |||||||||
dutyCycle | float64 | The 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)参数:
Name | Type | Description | |||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
taskHandle | TaskHandle | The task to which to add the channels that this function creates. | |||||||||
counter | const char [] | The name of the counter to use to create virtual channels. You can specify a list or range of physical channels. | |||||||||
nameToAssignToChannel | const 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. | |||||||||
sourceTerminal | const char [] | The terminal to which you connect an external timebase. You also can specify a source terminal by using a terminal name. | |||||||||
idleState | int32 | The resting state of the output terminal.
| |||||||||
initialDelay | int32 | The number of timebase ticks to wait before generating the first pulse. | |||||||||
lowTicks | int32 | The number of timebase ticks that the pulse is low. | |||||||||
highTicks | int32 | The number of timebase ticks that the pulse is high. |
3.DAQmxCreateCOPulseChanTime
1)用途:创建通道以生成由脉冲处于高状态的时间量和脉冲处于低状态的时间量定义的数字脉冲,并将通道添加到使用taskHandle指定的任务中。除非您选择不同的输出端子,否则脉冲会出现在计数器的默认输出端子上。
2)参数
taskHandle | TaskHandle | The task to which to add the channels that this function creates. | |||||||||
counter | const char [] | The name of the counter to use to create virtual channels. You can specify a list or range of physical channels. | |||||||||
nameToAssignToChannel | const 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. | |||||||||
units | int32 | The units in which to define pulse high and low time.
| |||||||||
idleState | int32 | The resting state of the output terminal.
| |||||||||
initialDelay | float64 | The amount of time in seconds to wait before generating the first pulse. | |||||||||
lowTime | float64 | The amount of time the pulse is low, in seconds. | |||||||||
highTime | float64 | The amount of time the pulse is high, in seconds. |
二、控制PWM脉冲产生的个数
1.DAQmxCfgImplicitTiming
1)用途:仅设置要获取或生成的样本数,而不指定计时。通常,当任务不需要采样计时时,应使用此函数,例如使用计数器进行缓冲频率测量、缓冲周期测量或脉冲序列生成的任务。对于有限的计数器输出任务,sampsPerChanToAcquire是要生成的脉冲数。
2)参数
taskHandle | TaskHandle | The task used in this function. | ||||||||||||
sampleMode | int32 | Specifies whether the task acquires or generates samples continuously or if it acquires or generates a finite number of samples.
| ||||||||||||
sampsPerChanToAcquire | uInt64 | The 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)参数
taskHandle | TaskHandle | The task to write samples to. | |||||||||
numSampsPerChan | int32 | The 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. | |||||||||
autoStart | bool32 | Specifies whether or not this function automatically starts the task if you do not start it. | |||||||||
timeout | float64 | The 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. | |||||||||
dataLayout | bool32 | Specifies how the samples are arranged, either interleaved or noninterleaved.
| |||||||||
frequency | float64 [] | Specifies at what frequency to generate pulses. | |||||||||
dutyCycle | float64 [] | 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. | |||||||||
reserved | bool32 * | Reserved for future use. Pass NULL to this parameter. |