News:

Let's find out together what makes a PIC Tick!

Main Menu

SHIn and Dwords strange behaviour ?

Started by kcsl, Mar 22, 2022, 06:22 PM

Previous topic - Next topic

kcsl

Trying to write some software that captures 32 bits of data from a long shift register chain and backhauls the data to a PC via serial. Nothing too strenuous, or so I thought.

After things not working as I expected some experimentation was in order.

I'm using 4.0.1 build 3 of the compiler.
The PIC is an 18F25K22


The following works and proves my hardware and software is fine.
SHIn SR_QH, SR_SRCLK, MsbPre_L, [ bytBank0\8, bytBank1\8, bytBank2\8, bytBank3\8 ]
hrsout bin8 bytBank0, " ", bin8 bytBank1, 13, 10 ' Only interested in the first 2 banks for now.

I changed to this which works but gives a compiler warning which just says "***! ***"
dim dwTemp as DWord

SHIn SR_QH, SR_SRCLK, MsbPre_L, [ dwTemp\32 ]
hrsout hex8 dwtemp, 13, 10     

I removed the \32; I shouldn't need it as dwTemp is a DWord variable so 32 bits.
The compiler warning goes away, but now it just returns all zeros as the result.

Next I introduced an array of Dwords (which is what I ultimately wanted to do)
This works fine which proves that HRSOut is happy with arrays of Dwords.
dim dwHeap[10] as Dword

bytHeapPointer = 5
SHIn SR_QH, SR_SRCLK, MsbPre_L, [ dwTemp\32 ] ' seem to need the \32
dwheap[bytHeapPointer] = dwtemp
hrsout hex8 dwheap[bytHeapPointer], 13, 10

Finally I tried this (which is my original code and started me down this investigative path) which just returns crazy results.
bytHeapPointer = 5
SHIn SR_QH, SR_SRCLK, MsbPre_L, [ dwheap[bytHeapPointer]\32 ] ' seem to need the \32
hrsout hex8 dwheap[bytHeapPointer], 13, 10

My conclusion is that you need to have the \32 and you can't use array elements (at least Dword ones) with the SHIn command.

Or am I just doing something wrong ?

Kind regards,
Joe



There's no room for optimism in software or hardware engineering.

Yasin

Necessary explanation is available on page 185 of the Positron8 manual.

QuoteBits is an optional constant specifying how many bits (1-16) are to be input by Shin. If no bits
entry is given, Shin defaults to 8 bits.

kcsl

Quote from: Yasin on Mar 22, 2022, 06:35 PMNecessary explanation is available on page 185 of the Positron8 manual.


That's brilliant Yasin... I thought I had to be doing something silly.
Thanks.

Regards,
Joe
There's no room for optimism in software or hardware engineering.

top204

#3
That is something I must add to future compiler builds, but it can be accomplished by something such as:

Dim dTemp As Dword

SHIn SR_QH, SR_SRCLK, MsbPre_L, [ dTemp.Word1\16 , dTemp.Word0\16 ]
MyDwordArray[bIndex] = dTemp


Where the Low and High words of the Dword variable are individually sent or received.