News:

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

Main Menu

A New Project Fixing a HiFi amp - First Problem Shift Registers

Started by Simon, Apr 11, 2021, 02:41 PM

Previous topic - Next topic

Simon

I thought I'd be the first to post in this brand new section of the forum as it's a project for me and it's an audio amplifier.

I fixed a Hifi amplifier for a good friend a few months ago and it sounded so good that I thought I'd buy one myself so I bought a broken one on ebay, it's a Cyrus 3 from the mid 90's.

As it turned out the part that was broken was the main processor, a Zilog Z86 which I know nothing about so I have opted for making a replacement processor using a pic and plugging it into the existing processor socket, I may also add a few extra functions if it works.

The processor controls most of the amplifier functions by sending out 6 bytes of data which is sent to 6 shift registers and the outputs from these turn on led's on the front panel, switch inputs and set volume, etc.

I have set up the same shift registers on a breadboard and started writing code to control these and this did work quite well at first but I've run into problems and I'm not sure what I'm doing wrong.

I've never actually used shift registers before so I think the problem is going to be fairly basic, for testing I have the shift registers connected to leds.

I send out 6 bytes (48 bits) of data 48 times, each time turning on one more bit, so another led lights up. This works perfectly, starts with no leds on and finishes with all on.

Next I send 48 bits all 0's but only the first 2 shift registers turn off the leds, the rest stay on.

Any ideas what I'm doing wrong? I have a logic analyser connected so will add a screenshot of that which may help.

Thanks
Simon



Simon

Pic is a 24FJ64GA004, shift registers are 74HC4094, chained using QS1 output to next data input.

Symbol DATA = PORTA.0
Symbol CLK = PORTA.1
Symbol Strobe = PORTA.7

Dim dT As Byte = 2
Dim index1 As Byte = 0
Dim index2 As Byte = 0
Dim testByte As Byte = 0
Dim testBit As Bit = 0
Dim sIndex As Byte = 0
Dim controlArray[6] As Byte
Dim arrayIndex As Byte = 0

For index = 0 To 5                              'zero all bits of control register
controlArray[index] = 0
Next


 
Low DATA
Low CLK
High Strobe

'*********************************************************************************************
'****************************************** MAIN *********************************************
'*********************************************************************************************
Main:

For index2 = 0 To 5                           'run through each bit of each byte and set
    For index1 = 0 To 7
        SetBit controlArray[index2], index1
        WriteSR()                             'send to shift register
        setSR()
        DelayMS 50
    Next
Next


For index = 0 To 5                            'clear all bits
controlArray[index] = $00
Next
WriteSR()
setSR()                                       'send to shift register
DelayMS 1000



GoTo Main
'*********************************************************************************************
'*********************************************************************************************
'**********************************************************************************************

Proc setSR()                                'send strobe pulse to shift register
DelayUS 10
Low Strobe
DelayUS 10
High Strobe
DelayUS 10
EndProc

'**********************************************************************************************
Proc WriteSR()
'send out 6 bytes of data (48 bits) to shift registers
'order data so that bit 0 of byte 0 is on first shift register Qo


For arrayIndex = 5 To 0 Step -1
    testByte = controlArray[arrayIndex]


    For index = 7 To 0 Step -1
        testBit = GetBit testByte, index
       
       
        DelayUS dT
        If testBit = 1 Then
        High DATA
        Else
        Low DATA
        EndIf
        DelayUS dT
        High CLK
       
       
        DelayUS dT
        Low DATA
        DelayUS dT
        Low CLK
    Next
   
Next


EndProc

Simon

DATA is data out of the pic to first shift register, DATA1, 2, etc are the links between the registers going down the chain

This is counting up, working ok

This should clear all the registers



Stephen Moss

Not done much with Procs but unless I am missing something should not
WriteSR() be WriteSR(Sent_Variable passed procedure) and
Proc WriteSR() be (Proc WriteSR(byvalue Recieved_VariableName as Byte)

Otherwise the variables inside the procedure are local to that procedure and not the values assigned to the variable in your main program. If I am correct then I think you would need to send each byte of the array to the procedure in turn as I am not certain passing an array would work.

Could         DelayUS dT
        If testBit = 1 Then
        High DATA
        Else
        Low DATA
        EndIf
        DelayUS dT
        High CLK
not be simplified to         DelayUS dT
        DATA = testBit
        DelayUS dT
        High CLK

Simon

QuoteNot done much with Procs but unless I am missing something should not
WriteSR() be WriteSR(Sent_Variable passed procedure) and
Proc WriteSR() be (Proc WriteSR(byvalue Recieved_VariableName as Byte)
I do generally like to keep variables local to the procedures but I've made the main 6 bytes of control data a global variable as many of the different amplifier controls will modify different bits of it. For example if the input is changed when a button is pushed that would be a separate procedure which would modify four bits within the 6 bytes and send them out and then the new 6 bytes are modified again by the next procedure that is called.

However I have been a bit lazy with making several variables global that shouldn't be and I'll tidy that up.

The reason I've used High DATA is just to make it more readable for me so I know it's an output pin rather than a variable, your way is neater maybe I'll adopt a different naming convention to show it's a pin instead.

Simon

It is working now, it was a wrong connection on the breadboard, I just knew it would be that and starred at it for ages yesterday going through every wire several times over. I have no idea how I couldn't see it yesterday but went straight to it today.  ::)

keytapper

There are few breadboards worth to use. The cheaper the weird. The steel for the hole clips aren't that much long lasting and tempting to leave a loose contact, in a short period of their life.

One more note, don't use big leads which cause a permanent deformation. 0.8 mm is the expected one.
Ignorance comes with a cost

Simon

QuoteThere are few breadboards worth to use. The cheaper the weird. The steel for the hole clips aren't that much long lasting and tempting to leave a loose contact, in a short period of their life.

One more note, don't use big leads which cause a permanent deformation. 0.8 mm is the expected one.

Oh I've got very nice breadboard, Global Specialities QT59S! so good they stopped making it and my pins are 0.6mm. I rarely use it these days preferring to just get a pcb made but I couldn't wait this time.
I would point out that all my connections are good and I have to take all the blame myself for putting one where it shouldn't have been.