Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

PIC16f870 Help please

dj_holmzy

Junior Member level 2
Joined
Jun 22, 2021
Messages
21
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
177
Hi,

I have a faulty chip that I cannot read and am trying to programme a new one for replacement. The chip is pic16f870 and it came from an amplifier. I have gone through great difficulty just to get the device to read the chip in MPLAB IDE.

I have attached the schematic of the circuit with the chip I need to programme. Any help would be greatly apprectaited as currently the amplifier does nothing as the chip is dead. Believe to be electrostatically shocked in circuit. Thank you
 

Attachments

  • S21-MI-CONTROL-CCT_.pdf
    133.5 KB · Views: 26

betwixt

Super Moderator
Staff member
Joined
Jul 4, 2009
Messages
15,021
Helped
4,894
Reputation
9,808
Reaction score
4,695
Trophy points
1,393
Location
Aberdyfi, West Wales, UK
Activity points
127,643
They are tough chips, I would check elsewhere before condemning it.

Does anything work at all, do any LEDs light up for example?
Have you checked the supply voltage is 5V? (Not 8V as marked on the diagram!)
Is the clock oscillator running?

The code inside it is probably protected so it can be verified but not read back.

Brian.
 

Dan1138

Member level 2
Joined
Jan 30, 2018
Messages
52
Helped
8
Reputation
16
Reaction score
10
Trophy points
8
Activity points
510
After looking at your schematic this circuit is a decoder for an infrared remote control.

The PIC16F870 is an ancient programmable controller. As you may know these device are blank when new.

Brian has said that these kinds of controller are code protected and as such the code programmed in them cannot be recovered with simple methods.

It seems after 20 years that the original equipment maker may have no idea of where to find the code for this device or how to program one for you.

There are quite a few new Microchip controllers that could be used in your board without any circuit changes. But you would need to create new code from scratch. This also seems to be an impossible task as you would need to know what kinds of signals need to be produced for each button on the remote control transmitter.
 

dj_holmzy

Junior Member level 2
Joined
Jun 22, 2021
Messages
21
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
177
Hi Brian,

On power on the Mute led lights up which is its normal operation.
I assume the power is correct or the led would not light at all. Its also marked 5v on the PCB itself where the ribbon cables goes.
I just powered the board with a 5v USB power supply and I tried to measure a frequency with my Voltmeter which has a Hz setting but nothing. Not sure if its suppose to give me anything. I have not seen this 3 pin blue oscillator before.

You maybe right as I used the IPX to read but said it was blank but verify seemed to be ok. But in IDE stated it was blank. To be fair the replacement chip also stated blank in IDE I did not attempt to verify the new chip.

Thanks for the input
 

Attachments

  • IMG_20210622_202609924.jpg
    IMG_20210622_202609924.jpg
    1.3 MB · Views: 21

dj_holmzy

Junior Member level 2
Joined
Jun 22, 2021
Messages
21
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
177
After looking at your schematic this circuit is a decoder for an infrared remote control.

The PIC16F870 is an ancient programmable controller. As you may know these device are blank when new.

Brian has said that these kinds of controller are code protected and as such the code programmed in them cannot be recovered with simple methods.

It seems after 20 years that the original equipment maker may have no idea of where to find the code for this device or how to program one for you.

There are quite a few new Microchip controllers that could be used in your board without any circuit changes. But you would need to create new code from scratch. This also seems to be an impossible task as you would need to know what kinds of signals need to be produced for each button on the remote control transmitter.
Hi,

I dont need remote codes, I just need to enable the switches to work to engage the relay. I thought it would be simple as input one when shorted would make output one high/low. It could be the same code as a simple light switch programme is it not?
 

betwixt

Super Moderator
Staff member
Joined
Jul 4, 2009
Messages
15,021
Helped
4,894
Reputation
9,808
Reaction score
4,695
Trophy points
1,393
Location
Aberdyfi, West Wales, UK
Activity points
127,643
The blue thingy is a ceramic resonator, it mimics a quartz crystal. It isn't as accurate but it is cheaper and smaller. They are very 'weak' oscillations around the resonator so it is quite likely your meter would stop it running anyway. The frequency is also 4MHz which is higher than most voltmeters can read.

Bear in mind that the 'verify' function of the programmer compares the code inside the device to the file used to program it. You do not have that file so you probably got a good result by comparing a blank with an empty file!

The Mute LED is driven by TR1 which inverts the logic levels fed to it from the MCU so the LED will always work in reverse to the others. Don't assume because it lights that the MCU is telling it to!

The actual operation of the device is quite simple. D1 to D15 encode the signals from SW1 - SW6 to a binary code to save pins, RA4 is a serial input from the IR detector and all the other pins are outputs to drive the LEDS and SKT1. It should be fairly simple to write your own code, especially if the remote sensor isn't needed.

Brian.
 

dj_holmzy

Junior Member level 2
Joined
Jun 22, 2021
Messages
21
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
177
Wow thanks for that information. Honestly I'm dead stuck, I have some experience in electronics and am comfortable with a soldering iron and also did some programming in school for a website but to do it for a chip I wouldn't even know where to begin.

Is there any chance of a template or default code I could use? I dont even need all of the inputs to work just a few is enough. I have time, experience is what I lack.

Thanks again for the input!
 

Dan1138

Member level 2
Joined
Jan 30, 2018
Messages
52
Helped
8
Reputation
16
Reaction score
10
Trophy points
8
Activity points
510
@dj_holmzy ,

You really did not give much to go on but this is what I could find:

This appears to be the device you are trying to repair:

AVI Lab S21 MI Integrated Hi-Fi Amplifier, Laboratory Series

Front
1571304219_1789.jpg


Back
1571304259_1249.jpg


IR Remote
reviews_choice_intamp2.jpg


Video

Article


Review


The company that made the AVI Lab S21 MI Integrated Hi-Fi Amplifier, Laboratory Series does not seem to exist anymore.

This is the old contact web page:

This may be all that is left:

For servicing of S2000 Series and Lab Series Products please contact:

PG Electronics who are accredited repairers for all early AVI electronics up to and including the Lab Series. Contact Phil Good by email pdg.electronics@gmail.com

Send them an email and ask, all you have is upside. The worst that could happen is they cannot help.


Mentioned in a web page last updated in 2013 link
 

Dan1138

Member level 2
Joined
Jan 30, 2018
Messages
52
Helped
8
Reputation
16
Reaction score
10
Trophy points
8
Activity points
510
Is there any chance of a template or default code I could use? I dont even need all of the inputs to work just a few is enough. I have time, experience is what I lack.

You say you have no experience with embedded firmware development. I can help you with that.

To set your expectations this kind of code would take an expert about two days to code and test. For someone with no embedded firmware experience it will take 1 to 2 weeks to learn how to install and use the tools, the 4 to 8 weeks to learn how to document, code and debug this kind of application.

If this seems like the kind of project you are willing to spend a few months on I can setup a code development repository on git hub and we can get started.

To start you need to describe, in detail, what needs to happen when each button is pressed and released.

With that description we can then create the code for the PIC16F controller.

You will need to get you own set of tools to build code and program the PIC16F controller.

The tools currently offered by Microchip for PIC16F development are complex to install and use. If you are new to this kind of coding it will require a few weeks just to learn how to use the MPLABX IDE after you get it installed.

Note that Microchip no longer supports the MPASM tool chain. MPASM was last supported in MPLABX v5.35

Here is an assembly language template for the PIC16F870 controller:
Code:
;
; File: 16F870_template.asm
; Target: PIC16F870
; IDE: MPLAB 8.92
; Assembler: MPASM v5.00 using absolute mode
;
; Additional files:
;   p16f870.inc
;
; Description:
;   This is a template for an assembly language program.
;   All this code does in setup the controller for all
;   of the GPIO pins to be digital inputs then count
;   in one 8-bit RAM memory location.
;
;                             PIC16F870
;                    +-----------:_:-----------+
;         ICD_VPP -> :  1 MCLRn         PGD 28 : <> RB7 ICD_PGD
;             RA0 <> :  2 AN0           PGC 27 : <> RB6 ICD_PGC
;             RA1 <> :  3 AN1               26 : <> RB5
;             RA2 <> :  4 AN2               25 : <> RB4
;             RA3 <> :  5 AN3           PGM 24 : <> RB3
;             RA4 <> :  6 T0CKI             23 : <> RB2
;             RA5 <> :  7 AN4               22 : <> RB1
;             GND <> :  8 VSS          INT0 21 : <> RB0
;       4MHz XTAL -> :  9 OSC1          VDD 20 : <- 5v0
;       4MHz XTAL <- : 10 OSC2          VSS 19 : <- GND
;             RC0 <> : 11 T1OSO          RX 18 : <> RC7
;             RC1 <> : 12 T1OSI          TX 17 : <> RC6
;             RC2 <> : 13 CCP1              16 : <> RC5
;             RC3 <> : 14                   15 : <> RC4
;                    +-------------------------+
;                              DIP-28
;
        LIST    n=0, c=160      ; make .LST file look pretty
        LIST    r=dec           ; use decimal (not HEX) numbers by default
        errorlevel -302         ; Suppress the not in bank zero warning
;
; Inculde definitions for device specific Special Function Registers
;
#INCLUDE "p16F870.inc"
;
; Setup all configuration word bits
;
__CONFIG _XT_OSC & _WDTE_OFF & _PWRTE_OFF & _CP_OFF & _BOREN_ON & _LVP_OFF & _CPD_OFF & _WRT_ALL

;
; Reset vector
;
    org     0x0000                  ; processor reset vector
    GOTO    START                   ; go to beginning of program
;
; Interrupt Vector data
;
  cblock 0x70
    WREG_Save : 1
    STATUS_Save : 1
    PCLATH_Save : 1
  endc
;
; Interrupt Vector code
;
    org     0x0004                  ; interrupt vector location
    movwf   WREG_Save
    movf    STATUS,W
    movwf   STATUS_Save
    movf    PCLATH,W
    movwf   PCLATH_Save
;

; Put interrupt handler here

;
ISR_EXIT:
    movf    PCLATH_Save,W
    movwf   PCLATH
    movf    STATUS_Save,W
    movwf   STATUS
    swapf   WREG_Save,F
    swapf   WREG_Save,W
    retfie
;
; Main data
;
  cblock    0x20
    Count   : 1                     ; One byte of data
  endc
;
; Main code
;
START:
    clrf    INTCON                  ; Disable all interrupt sources
    banksel PIE1
    clrf    PIE1
    clrf    PIE2

    movlw   0xFF                    ;
    movwf   TRISA                   ; Make all GPIO pins inputs
    movwf   TRISB
    movwf   TRISC

    movlw   0x06                    ;
    movwf   ADCON1                  ; Make all GPIO pin digital I/O
;
; Application start
;
    banksel Count
    clrf    Count
;
; Application process loop
;
ProcessLoop:
    incf    Count,F
    goto    ProcessLoop
    end
 
Last edited:

betwixt

Super Moderator
Staff member
Joined
Jul 4, 2009
Messages
15,021
Helped
4,894
Reputation
9,808
Reaction score
4,695
Trophy points
1,393
Location
Aberdyfi, West Wales, UK
Activity points
127,643
It may look daunting if you have never done any programming on MCUs before but it really isn't that difficult. I think I would probably tackle it in 'C' rather than assembly language but either way it isn't as hard as it looks.

Start by working out exactly what happens when each of the switches is operated, you will need to know this to create a flow diagram. For example, what happens if you press SW1 then press SW2, what did SW1 actually do and what effect if any did SW2 have on it. Some switches may interact with each other, you need to take that into account. Also look at what happens if you press a switch twice, does it 'stay put' after being pressed once or does it alternately switch something on then off again.

From there is is a relatively simple task to write a program to read the switches and produce the appropriate output signals.

Brian.
 

dj_holmzy

Junior Member level 2
Joined
Jun 22, 2021
Messages
21
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
177
Its a whole different world I wasn't even aware of! And I really appreciate the help. I'll work out the functions and report back shortly.

As far as IPX/IDE goes it seems all I need to do is to upload the file and click programme the chip button LOL. It needed a compiler which I also downloaded. As mentioned it was trying to read the chip and was communication with it at least.
 

dj_holmzy

Junior Member level 2
Joined
Jun 22, 2021
Messages
21
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
177
I have emailed Phil in desperate plea for the codes, all I can do is wait but I'm not holding my breath! LOL

OK I have figured out the switches. When pressed it should choose the input associated with the switch and it should stay on until another switch is selected.
If you same switch is selected it should do nothing!

SW1 = Disc = LED1

SW2 = Video = LED2

SW3 = CD = LED3

SW4 = A.V. = LED4

SW5 = Tuner = LED5

SW6 = Tape = LED6

SW7 = Record = LED7

LED 8 = Mute
 

Dan1138

Member level 2
Joined
Jan 30, 2018
Messages
52
Helped
8
Reputation
16
Reaction score
10
Trophy points
8
Activity points
510
The schematic looks like the PIC16F870 is use to do these things:

1 - Replace mechanical switches that select audio source for the power amplifier

2 - Replace mechanical switches that select audio source for the recorder

3 - Decode an infrared remote control for volume up, down, mute and audio source selection for the amplifier and recorder.

Depending on how the amplifier is designed the audio source for the recorder may or may not be independent on the source selected for the amplifier.

I could not find anything that describes how the AVI S21 MI user interface works.

Do you have a user guide or owners manual?
--- Updated ---

I found a user manual for the AVI Lab S21 MI amplifier here:


But it is worthless for the purpose to create code for the PIC16F controller because it does not describe how the front panel buttons work to select audio sources.

Is does tell us what infrared control is used: "All AVI products now use standard Philips RC5 codes"

This does not help that much as we still have no clue as to which RC5 command codes are associated with what outputs the PIC16F must assert and release for that function.
 
Last edited:

dj_holmzy

Junior Member level 2
Joined
Jun 22, 2021
Messages
21
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
177
I used to have one many years back, it doesnt say much.

I don't need the recorder function or remote function, just need to engage the raly so I can actually get some sound! Bit silly really an expensive machine becomes a door stop due to an IC.
 

Dan1138

Member level 2
Joined
Jan 30, 2018
Messages
52
Helped
8
Reputation
16
Reaction score
10
Trophy points
8
Activity points
510
I will create an application for you that does what looks correct.

If you have a service manual that shows what the outputs of the PIC16F870 are connected to in the amplifier I can keep it from blowing stuff up.

You are also going to need to describe exactly which Microchip tools (IDE, compiler etc.) you have installed and working.

Be sure to mention the complete version numbers of the IDE and compiler you have installed.

I have a lot of Microchip tools installed on my system. I could easily create a project that you cannot build or program in to a target device.
 
Last edited:

dj_holmzy

Junior Member level 2
Joined
Jun 22, 2021
Messages
21
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
177
I got a reply back from Phil, he does not have the code. I'm yet to hear back about the additional service manual.

The IDE version is V5.5 and the compiler is XC8.

I just found the other part of the service manual!

How do I measure it? Can you explain please.

Thanks for the help guys!!
--- Updated ---

Can the chip be bypassed somehow? I wish I could understand the schematic....
 

Attachments

  • S21-MI-PREAMP-CCT_.pdf
    178.5 KB · Views: 4

Dan1138

Member level 2
Joined
Jan 30, 2018
Messages
52
Helped
8
Reputation
16
Reaction score
10
Trophy points
8
Activity points
510
The schematic page you post seem to have all the information I would need to create the code you want and not cause the relays to close in a bad way.

You could ask Phil to describe how the buttons and LEDs on the front panel interact.

Like when are the lower row of LEDs (LED9 - LED13) suppose to light up

I will write the code to toggle the one that corresponds to the selected source when the REC button is pressed,

The code I plan to implement will:

At power start assert turn on the MUTE light with all no sources selected.
Wait one second
Poll source select buttons until a selection is made, then Light the selected source.
Wait one second
Turn off MUTE
Poll source select and REC buttons until a selection is made, then Light the selected source or toggle the REC light, loop.

Other enhancements are possible such as to toggle the MUTE when the source select button is pressed for the currently selected source.

I will setup an MPLABX project using MPLABX 5.45 and XC8 v 2.31, this is what I have installed, and will build with what you have.

I will need to study the schematic you posted to be certain what I propose will work.
 

dj_holmzy

Junior Member level 2
Joined
Jun 22, 2021
Messages
21
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
177
That's amazing really much appreciated.

I will wait for a response from Phil in regards to previous message first then take it from there.

I see the logic but I guess the code is something completely different.

The REC function is not required at all. The LED 9-13 can be ignored as it does not affect the normal operation of the amplifier.

On power up the MUTE is on by default and it seemed to still come on even with the fault. I would say this is better without the "Wait one second" as previous it was instantaneous. Not sure what "Poll" means either to be honest.

At power start assert turn on the MUTE light with all no sources selected.
Wait one second
Poll source select buttons until a selection is made, then Light the selected source.
Turn off MUTE

Just trying to get the amplifier to turn on seems a monumental task, not like the good old days LOL.

I don't know how much time you have on your hands to go through the coding process too as I am just gob smacked by all this. I have flashed BIOS/Phones etc but not seen the coding that goes into them...
 

Dan1138

Member level 2
Joined
Jan 30, 2018
Messages
52
Helped
8
Reputation
16
Reaction score
10
Trophy points
8
Activity points
510
I have created an MPLABX project for developing the code you need.

Find it in my git repository here: https://github.com/dsoze1138/16F870_AVI_S21_MI

This code builds and should run in your hardware.

IT WILL NOT MAKE YOUR AMP WORK!

The purpose is to validate that you can build the code and program it in to your controller.

My approach here is to test our development tools and not damage your amplifier in the process.

Reply when you get my code to run as I expect or have any issues with the tools.

In essence this code should make the (record) light flash 2 times per second.

When we get that to work we will validate what the buttons do.

There is a problem with the schematic. If the PCB is assembled as shown then SW4 and SW6 both use the same encoding.

This cannot be the way this is actually built so there must have been a change in the final production that did not get documented.

Post a photo of the back of the PCB and we can work out what is true.
 

LaTeX Commands Quick-Menu:

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top