LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Reading a bitstream using digital I/O/counter

Hello everyone,

 

 

I have a device needs 10x period 80% PWM signal, 10x period 50% PWM signal and 10x period PWM Signal to activate sending serial data (baud rate 9600). How can I read the serial bitstream using a digital lines or counters (NI USB 6341). There’s an example program?

 

thanks a lot for your help in advance

0 Kudos
Message 1 of 16
(3,410 Views)

Hi nbnnnbn,

 

Can you give a little bit more detail? In particular,

  1. Do you want to output the PWM signal, or is that provided elsewhere (by the device, perhaps?)
  2. Your device is sending data at 9600 baud. You want to read this data using the NI USB-6341. How is the data related to the PWM signal?

Please clarify what you're trying to do and I'm sure it should be straightforward enough to provide either a built-in example or a modified example here for you to look at.


GCentral
0 Kudos
Message 2 of 16
(3,358 Views)

Thank you for your replay.

 

I am sending PWM with 300Hz frequency and duty cycles. Device replay with sending back serial data at 9600 baud.

I want just to read this serial data (device response) using timed digital oi or counter. 

0 Kudos
Message 3 of 16
(3,348 Views)

I'm using Digital input P0.5 to read bitstream at baud rate 9600. i have timing Problem. any suggestions?

0 Kudos
Message 4 of 16
(3,295 Views)

Hi nbnnnbn,

 

i have timing Problem. any suggestions?

You have way more problems than just timing…

 

What's the point of this 10ms wait in the loop? Delete it! DAQmx will provide proper timing…

When you want to read your digital data you should sample at a higher sample rate! Ever heard of Nyquist and Shannon?

Why do you read a single bit, just to convert it to a 0/1 string?

 

Way to the solution:

- use a higher samplerate

- decimate the read data after syncing to your device.

- read more than just one sample per DAQmxRead call. (Good combinations would be 57600 S/s and 5760 samples to read…)

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 5 of 16
(3,281 Views)

Is there any reason you cant just use a serial port to read back the serial data?

0 Kudos
Message 6 of 16
(3,277 Views)

I'm with deceased - if this is something common like RS232 then there are many cheap and simple hardware solutions that will allow you to use things like the VISA Read node, and make the programming massively simpler.

 

If instead this is something more like SPI, then (although there are still hardware solutions) perhaps you have some more information to share - for example, do you also have a clock line? You could use that to control the rate of your data acquisition.

 

If for whatever reason those are unpalateable, then you can do it manually as suggested by GerdW with oversampling and then parsing in a similar way to what you uploaded. Follow the instructions given in his post and you should be fine 🙂


GCentral
0 Kudos
Message 7 of 16
(3,274 Views)

thanks a alot for your help. it works. i used Timing: Change Detection (See vi readSerialData.vi).

 

I have an other Question. i tried to create PWM signal using digital waveform:

frequency 300 Hz ±5
1. Duty cycle 80 ±5 (10 periods)
2. Duty cycle 50 ±5 (10 periods)
3. Duty cycle 10 ±5 (10 periods)

 

Problem is, i can not see the created PWM signal in Oscilloscope. the Amplitude of the signal is -+1V (desired range 0v-5v) in the analog Waveform Graph?? (Test120.vi )

 

sorry for my english 🙂

 

 

 

 

 

 

Download All
0 Kudos
Message 8 of 16
(3,259 Views)

Hi nbn,

 

you forgot to attach the subVI of your "Test120" VI…

 

i can not see the created PWM signal in Oscilloscope.

Because you stop the DAQmx task immediatly after writing the digital data to the DAQmx output buffer!?

Wait until the DAQmx task is finished!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 9 of 16
(3,251 Views)

thank you for your replay. how can wait until DAQmx task finish? i want to finish the task  after sending PWM signals. i modified the Vi

0 Kudos
Message 10 of 16
(3,246 Views)