Serial data out, bit banging and threading in c#

Thread Starter

hunterage2000

Joined May 2, 2010
487
I am trying to get my head around threading in C# and I want to run 3 methods in parallel.

The attached image shows the timing waveform for a SIPO Shift reg.

The SHCP is the shift reg clock, DS is the serial data out and STCP is the storage register.

SHCP will be generated using the RS232 TXD pin at 9600 Baudrate, DS with Dtr at 1 bit per ms and STCP with CTS at a ms.

The idea is to:
1. Tick a combination of 8 checkboxes then press a SEND button
1. Start SHCP which will have a start bit
2. wait 1ms then start DS so SHCP will be at the first 0
3. For each of the 8 cycles, 8 bits will be shifted with DS on the rising edge of SHCP and leading SHCP by 0.04ms
4. After the 8th bit, STCP will go HIGH for 1ms
5. DS will now be on the Shift reg parallel outputs.
6. GO BACK TO 1.

Will running 3 threads do these in parallel so the 3 waveforms match up?
 

MrSoftware

Joined Oct 29, 2013
1,860
Your attachment didn't make it. Keep in mind, your 3 threads are not guaranteed to get similar processor time and you will most likely have to manually synchronize them if the timing between their operations is important.
 

WBahn

Joined Mar 31, 2012
26,029
It seems like you are trying to work at two ends of a spectrum that are somewhat mutually exclusive. By using a language like C#, you are trying to work at a very high level and encapsulate all the low-level stuff in a black box that just works to provide the high-level behaviors you expect, but then you are wanting to bit bang port pins which is about as low-level and the furthest thing from encapsulation as you might imagine. You might be in for a lot of hidden gotchas as you try to make this work.
 
Top