Serial to parrallel conversion

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
stco_1575631
Level 2
Level 2
10 replies posted 5 replies posted 5 sign-ins
Hi,
I've only played with PSoC till now, but at last, I have got a real application, and I'm not sure of the best way to proceed. I am trying to read several 'Chinese scale' as used in verniers etc, as well as other format sensors.
Examples can be found on the web at Yuriys toys, Shumatec etc. I would like a  solution that could be configurable. They all have a lot in common.
  1. They are all 24-bit data(or multiples of) with a clock and data on positive or negative edge triggering
  2. There is a gap between data packets that is orders of magnitude greater than the clock to distinguish start.
 
So it looks like all I need is a timer with the clock on reset to clear it if started near a new packet. The output of the timer then enabling a 24-bit shift register.
 
The problem is I'm struggling to figure out how to configure the shift register. I would have thought that at the terminal count (24 ) there would be an interrupt/DMA transfer to save the parallel data to memory. The shift out interrupt is ( I think) generated on the NEXT pulse, which of course I don't get as it's the first bit of the next data block. I looked at using the Timer block to create an SS signal for an SPI, but that's only 16 bit, so no good. I could use a 24 bit counter, but that seems overly complicated. Could anyone point me in the right direction, please? If that involves verilog I will have a problem as I need a proof of concept asap and I have Zero experience with Verilog.
Many thanks
Steve
0 Likes
1 Solution
lock attach
Attachments are accessible only for community members.

Steve,

Attached is a DigiMatic Receiver project.  It should be very close to match the specs and timing of the Chinese scales link you provided.

Since I don't have a DigiMatic device (which transmits), I added a DigiMatic Tx simulator.

I also provided a UART debugging comm port to display the returned values from the DigiMatic Rx.

This should be a good starting point.

CORRECTION!!!

A closer inspection of the links you provided requires me to issue a correction.

The attached project is called DigiMatic however it is more accurate to say the protocol support within is the Chinese Scale protocol.

Len
"Engineering is an Art. The Art of Compromise."

View solution in original post

0 Likes
14 Replies
Len_CONSULTRON
Level 9
Level 9
Beta tester 500 solutions authored 1000 replies posted

Steve,

I'd like to try to help.  However your description as a bit confusing.

What is your INPUT to the PSoC?  Serial?  UART, SPI or I2C type?  Parallel (24-bit)?

What is your desired output from the PSoC?  Serial? UART, SPI or I2C type?  Parallel (24-bit)?  Other?

In your description you reference a 24-bit shift register.  I'm confused as to why a shift register is necessary.

For example if you need to output 24bits of serial data, you can use the CPU to dump 8-bits a time (3 times).

Len
"Engineering is an Art. The Art of Compromise."
0 Likes

Hello Len, Sorry for causing any confusion. Many forums don't like direct links to other sites , so I did suggest where to go to find further information on these scales, as there are a variety of variations on them, and they explain much better than I can. But its basically a two wire stream with a clock and data in,  very much like SPI in, but you need to qualify a new data packet from the dead period in between. 

So I need to capture the 24 bit serial stream and collect it as a 24 bit 'word' for subsequent processing and output to a device be that serial or LCD.

It is a trivial task with a small micro (eg pic12 -18 or atmel etc) to do one channel either using interrupts or simply reading and analysing each bit (clock is usually only 10's of kilohertz, but becomes much trickier in the CPU if you have 4+ all happening asynchronously, I tried it with an ESP32 with 4 channels, but it wasn't reliable, and it struck me that a psoc doing this in hardware would be much easier (IF you know how to do it!!)

I trust this clears the confusion, and look forward to your suggestions

Thanks

Steve

 

 

0 Likes
lock attach
Attachments are accessible only for community members.

Steve,

Please include at least one link to your external site for the protocol you are trying to implement.

In advance of this information, I have attached an example project that may be useful to you.

This project uses the CPU to only load the next 24-bits into a SPI component.  The SPI provides the 2-wire CLOCK and DATA.

It also incorporates a timer to provide the inter-packet timeout between 24-bit transfers.

To prove this HW circuit transfers data only when data is available, I placed a task flag to only transfer the 24-bit data for 1 second, wait for 1 second and start transferring data again. 

The beauty of this technique is that the CPU is used very minimally.   The PSoC HW is tuned to do most of the work.

The CPU only used to push the 24-bit data into the SPI 4-byte FIFO.

The SPI HW transfers the 24-bits (3-bytes) to the 2-wire bus.  Once this is 'DONE', it triggers a Timer to time out the inter-packet delay.

Once the delay is completed, an ISR is run to transfer the next 24-bit value if available.

In theory, it is possible to use DMA to further minimize CPU overhead.   I thought is was simpler to understand what was happening with an ISR instead.

Not knowing the protocol you are trying to implement, I assigned the Clock-edge-to-data, Clock rate, inter-packet delay values.

Note:  If you need multiple channels, I was able to create 6 of these circuits before getting the Resource exceeded error.

Len
"Engineering is an Art. The Art of Compromise."
0 Likes

Thanks Len,

That certainly looks on the right lines. I'll check it out as soon as I can and get back to you.

Here is one link to a type of scale, as I said there are many more, but this explains the principle

http://shumatech.com/support/chinese_scales.htm

Once again, many thanks

Steve

0 Likes

Steve,

Thanks for the link.  It answers some of the questions.

The project I attached earlier is for the PSoC to OUTPUT (Tx) the DigiMatic protocol.  Not to receive the DigiMatic protocol.   I now realize that you what to INPUT (Rx) the protocol.

This project is usefully for Simulating the DigiMatic Protocol from a sensor device.

Hold tight.  I'm in the process to create a DigiMatic Rx device for the PSoC.

 

Len
"Engineering is an Art. The Art of Compromise."
0 Likes

Thats brilliant thank you,

A bit more info on some of the other scales out there 

https://www.yuriystoys.com/search/label/Digital%20Scales%20and%20Calipers

You have to go through a few blogs to get it all.

Its a bit different to the Mitutoyo ( which would also be good to have.)

Looking forward to your answer.

Thanks 

Steve

0 Likes
lock attach
Attachments are accessible only for community members.

Steve,

Attached is a DigiMatic Receiver project.  It should be very close to match the specs and timing of the Chinese scales link you provided.

Since I don't have a DigiMatic device (which transmits), I added a DigiMatic Tx simulator.

I also provided a UART debugging comm port to display the returned values from the DigiMatic Rx.

This should be a good starting point.

CORRECTION!!!

A closer inspection of the links you provided requires me to issue a correction.

The attached project is called DigiMatic however it is more accurate to say the protocol support within is the Chinese Scale protocol.

Len
"Engineering is an Art. The Art of Compromise."
0 Likes

Wow, thats fantastic !!

Thanks Len.

I will try connecting to my hardware , probably over the weekend and let you know how I get on.

It did issue one warning which I will investigate, it may be nothing

Warning-1367: Hold time violation found in a path from clock ( Clock_1 ) to clock ( dm_clk/q

Thanks so much. Let you know how I get on.

Steve

0 Likes

Steve,

You're welcome.

I got the warning too.  However the data from the Tx stimulus was Rx'd correctly.

Len
"Engineering is an Art. The Art of Compromise."
0 Likes

Steve,

Based on the Chinese Scales link you provide, how does someone connect to the PCB traces for the signals?  They're not 0.1 inch pitch.

Len
"Engineering is an Art. The Art of Compromise."
0 Likes

Hi Len,

In answer to your question , not easily!!! They did at one time supply cables that plugged in, but it was useless. The only real answer is to solder them in, then pot them. I saw someone trying to 3d print one, but I wouldn't rely on it. A MUCH better alternative is the SHAHE scale such as

https://www.amazon.com/Digital-Readout-0-150mm-Accurate-Machines/dp/B089ZSG84J/ref=sr_1_1?dchild=1&m...

This uses a mini USB connector, but that is none standard pinout to avoid damage if you plug one in to a USB port.

All of this is explained in

https://www.yuriystoys.com/2019/01/shahe-dro-scales.html

but you have to search around for the data. This is the unit I am specifically trying to target. And here's some oscilloscope grabs

ShaheData.png

 

Shahegap.png

 

As you can see its pretty darn slow. The data period is approximately 10mS and the gap Around a 100mS. These signals are being fed in to your code as (blue)clock and (yellow) data. I did run your software, and it seemed to work with your simulated data, however that was running around a 1,000 times faster, with timing in uS rather than mS from my scale. I did try increasing the PWM time, but no luck. I removed all of your generator components.  I was thinking of doing a simple pin read to get to the end of the first 24 bits of data, and then start the SPI. It should stay in synch after that!!

Any ideas?

Steve

0 Likes

Steve,

I have a Harbor Freight Caliper with the 4-pin connection.

You should be able to change the timing parameters on my program pretty easily.

You need to determine the incoming CLK.  It appears from the scope plots to be 3KHz.  Then change Clock_2 to CLK*2 which would be 6KHz.

Then adjust the PWM_1 period to allow a maximum 30ms between terminal counts (tc).  That would set the period to 200.

It appears from the scope plot that there is only one 24-bit data from your sensor.  Therefor you can leave the compare alone.  Just use rx_data[0].

 

Len
"Engineering is an Art. The Art of Compromise."
0 Likes
lock attach
Attachments are accessible only for community members.

Hello Len

I tried modifying as you suggested (I think!!), and removed all tx routines, but I get absolutely no output on the terminal.

I have attached my modified project, and a screenshot

ShahewData0valid.png

showing Data0Available(in pink). What am I missing?

0 Likes

Steve,

Do me a favor.

Capture two data packets of the Clock and Data signals on the scope and send me the .csv results.

With the .csv file of these signals, I can try to replicate your data input with a signal generator into your project.

Len
"Engineering is an Art. The Art of Compromise."
0 Likes