PIC 12F683 Infra Red Extender

Circuit : Tom Borremans, Belgium
Email :

Description
This is a new digital version of the Mark 4 extender circuit, by Tom Borremans. This new version has all the remote control signals precisely times by a Microchip PIC 12F683. The input uses a TSP38238 receiver having a 180 degree range and uses a BS170 MOSFET output transistor and has a 6 metre range.

Notes

This infra red remote control extender circuit is based on the Mark 4 version found here. The PIC 12F683, manufactured by Microchip, does all the work of the 555 timer but without the need for external timing components.
It has been programmed to generate a 38KHz carrier of general purpose pin 2 of the PIC12F683. The input signal from a remote control is received by a TSOP1838 receiver, and connected to General Purpose pin5 (GP5), set up as an input. The TSOP 38238 already contains an internal 30k pull up resistor, so no external pull up is required.

 


Programming the PIC

Programming a PIC microcontroller is done in two steps:
  • Writing the Code
  • Transferring the Code to the PIC
  • Writing the Code

    The software was wrote in MPlab X IDE which is cross platform and can be downloaded for Windows, Linux and Mac OS. The software can be found here.. MPLab X is an Integrated Desktop Environment and allows you to write the code in C language, and MPLAB will convert the code into a low level hexadecimal (HEX) format. The HEX file contains all the instructions necessary for the PIC micro controller and is all that is needed to program the PIC. Although you can program a PIC in Assembler language, MPLAB uses C which is a higher level language than Assembler.Please note that MPLAB only creates the Hex code for a PIC. MPlab can work with MPlabs own hardware, the PICkit programmer Mk1,2,34 for example. You can also build a clone of the PICkit mark2 programmer instructions on this link.

    Transferring the Code to the PIC

    To program the PIC, you need a programmer (these can be home made DIY or sold separately), a computer (either laptop or desktop PC), and a cable to connect between PC and programmer, and software to transfer the HEX code from the programmer to the PIC.

    Once the programmer has been connected to the computer, the HEX file created in MPLab is loaded by the programmer software and transferred into the PIC. Once programmed, the PIC is removed from the programmer and placed in the circuit. Programmers are connected either to a Serial RS232 port like the JDM programmer. The RS232 needs a "real" RS232 port as the higher 12to 15V signal is used to flash the PIC. As RS232 ports are less common on newer computers a USB programmer like Open Programmer may be used.



    Building a PIC Programmer

    Tom originally made a RS232 serial Programmer based on a modified JDM design (shown left). The schematic and assembly can be found on Rado's web site
    A JDM programmer is not neccessary as you can use a USB programmer like the Open Programmer (shown right). The Instructables site also has details for making a PIC USB programmer. Programmer software like PICpgm can be used with both types of hardware programmer.

    Now if you decide to make your own programmer, you must already have access to a PIC programmer because the programmer requires a programmed PIC, this is the chicken and egg scenario. The alternatives are to use an Arduino board or buy a ready assembled PIC programmer.


    Using a PIC Programmer

    As shown in the two photographs above, PIC programmers connect to your computer using with USB or a serial port. To use a Serial programmer like the JDM, it is vital to have a real COM port from a desktop PC itself. Although USB to serial adapters are available, they cannot supply enough voltage to program a real PIC, so avoid these. Also there is a tendency not to include serial or RS232 ports on modern computers anymore, so a USB programmer is the better option. A USB programmer also works well on a laptop. They contain a SMPS onboard that creates the 12,5 - 13 volts needed to program a pic successfully. A zero (space) is Asserted +3 to +15 V and a high (mark) is Deasserted −15 to −3 V RS232 on wikipedia

    To program the 12F683 PIC Tom used PICpgm. Picpgm also has a linux and mac osx version + It supports more pic types. you can see our 12F683 in the list.

    Program Code for PIC 12F683

    The main program code for this project has been wrote in the C language.

    The PIC has also been programmed to use the internal RC oscillator --> no crystal or caps needed. As well as internal POR ( power on reset ) --> so also no rc reset circuit needed. Once powered up, any Incoming logical 0 generates a 38khz carrier to the output IR led via MOSFET. A Logical 1 turns the MOSFET low and IR led off. That's all it does. just a few lines of code.

    Tom has also provided ample comments for anyone wishing to look at the code. I wanted to share this code because it is not mush of a secret or difficult code that asked mush time to write / debug. It's pretty much very easy to understand what the code does and it could be a great learning project for a total novice in chip programming.



    // CONFIG PART
    #pragma config FOSC = INTOSCIO	// Oscillator Selection bits (INTOSCIO oscillator: I/O function on RA4/OSC2/CLKOUT pin, I/O function on RA5/OSC1/CLKIN)
    #pragma config WDTE = OFF		// Watchdog Timer Enable bit (WDT disabled)
    #pragma config PWRTE = ON		// Power-up Timer Enable bit (PWRT enabled)
    #pragma config MCLRE = OFF      	// MCLR Pin Function Select bit (MCLR pin function is digital input, MCLR internally tied to VDD)
    #pragma config CP = OFF         		// Code Protection bit (Program memory code protection is disabled)
    #pragma config CPD = OFF        		// Data Code Protection bit (Data memory code protection is disabled)
    #pragma config BOREN = ON       	// Brown Out Detect (BOR enabled)
    #pragma config IESO = OFF       		// Internal External Switchover bit (Internal External Switchover mode is disabled)
    #pragma config FCMEN = OFF      	// Fail-Safe Clock Monitor Enabled bit (Fail-Safe Clock Monitor is disabled)
    
    #include 
    
    #define _XTAL_FREQ  8000000     	// Let the compiler know we will be running at 8MHz
    
    // MAIN LOOP
    
    void main(void) {			         // Enter the main loop
    	OSCCONbits.IRCF = 0b111;    	// Select 8MHz clock
    	TRISIO = 0b111000;          	// GPIO5/4/3 inputs, 2/1/0 outputs
    	ANSEL = 0;                  	// Force all GPIO pins to digital mode
    	while (1)	   		         // Loop forever
        	{				               // The TSOP outputs a ttl level 1 when idle. So a ttl 0 level is in fact a logical 1
            	while (GPIObits.GP5==0) // So We have to invert our thinking and ttl 0 = logic 1. Using GPIO pin 5 as input
            	{			               // When logic 1 enter the 38Khz generator loop. 
                		GPIObits.GP0=1;	// Using GPIO pin 0 as the generator output. Switch GPIO 0 to ttl 1
                		__delay_us(10);	// wait 10 µSec
                		GPIObits.GP0=0;	// Switch GPIO 0 to ttl 0
                		__delay_us(10); // wait 10 µSec
            	}			                 // Repeat as long GPIO5 stays at logic 1. 50/50% duty cycle ( 37,8Khz in real life )
            GPIObits.GP0=0;			    // When in logic 0 state switch off BS170.
        	}				                // keep waiting for incomming ttl 0 on GPIO5 for ever
    }				                  	// Close main loop
    

    Download Code

    This file contains the C source code for anyone wishing to modify

    Download the HEX code, this is the only file required for your programmer.

    Pictures of Prototype

    The right image shows the original circuit on breadboard for testing. Once the design was tweaked and finished the final circuit is made on veroboard (shown left).

    Also on the veroboard layout, Tom used a USB cable and cut it in half. The outer wires (usually red and black) as seen, are the USB power cables. Note also the twisted pair white/green cable. This is used to wire the final IR emitter diode shown in black.

    Twisted pair cable can be CAT5 or old telephone cable and has an advantage over speaker cable and bell wire, because it has a lower capacitance. Long cables and high capacitance limit high frequencies and on pulse circuits, skew the rise and fall times, which can lead to instability, or not being able to control any appliance at all.


    Power Consumption

    The circuit requires 5 Volt and can beconveniently powered from a USB port. The USB port can supply up to 500mA of power, this circuit on standby draws 4mA. When activated the MOSFET applys the full USB voltage (5 Volts) less the forward voltage drop of the IR photo diode (about 1.5 Volts) divided by R1 the curremt limiting resistor. The total load is:

    Total Power Consumption (5-1,5)/47= 75mA +4mA <= 80mA

    This is well below 100mA and the total USB current limitations.

    Microchip PIC 12F683 Pinout

    Microchip Datasheet

    The pdf datasheet for the PIC12F683 can be found here.
    Circuit Exchange International Return to Microcontroller Circuits http://www.zen22142.zen.co.uk