File: /media/j/texas/my msp430/g3tr/g3tr.c Pagina 1 di 5 /+ filename: g3tr.c G3TR means: Giuseppe Talarico Transistor Type Recognizer This version is for launchpad MSP430 Just only two 10K resistors and a serial terminal program are needed to implement a simple and powerfull digital Transistor Tester. The circuit allows to test any type of transistor ( npn,pnp, n-channel, p-channel ) both low or High Power. The program tell us if the transistor under test is working or not and which is his type for example: NPN-BJT, PNP-BJT, NCHANNEL-MOSFET, PCHANNEL-MOSFET. The program test diode too and tell us where the Anode is attached ( RED CABLE or BLACK CABLE) Devices broken or shorted are decoded too. Here the circuit: ---------------------------------------------------------------------> to GATE ----------------------- ------- - VCC GND - -- 10K -------- P1.0 P2.6 - ------- <-- P1.1(TX_UART) P2.7 - to SOURCE <--- P1.2 TEST - BTN1 --> P1.3 RST - -------- ----------------> P1.4 P1.7 -------------- 10K -------> to DRAIN -------> P1.5 P1.6 --> GREEN_LED -------- ----------------------- ----------------------------------------------------------- date: mercoledì, 4 maggio 2011 Author: Giuseppe Talarico (www.giuseppetalarico.wordpress.com) / // /opt/msp430-gcc-4.4.5/bin/msp430-gcc -Os -mmcu=msp430x2231 g3tr.c tx_uart_lib.c -o g.elf // Connect launchpad to pc-usb. // The following three command are needed to load and run the file g.elf: // mspdebug rf2500 // prog g.elf // run #include <msp430g2231.h> // registers definitions #include "tx_uart_lib.h" //----------------- hardware abstractions --------------------- #define PORT1_DIR P1DIR #define PORT1 P1OUT #define BTN1 3 // bit P1.3 #define DRAIN_IN 5 // bit P1.5 if n-channel (npn) this bit is!(r_gate_out) #define BJT_MOSFET_IN 4 // bit P1.4 if P1,4 = L the devices is a MOSFET // if P1.4 = H the devices is a BJT #define R_GATE_OUT 0 // bit P1.0 gate or base driver #define SOURCE_OUT 2 // bit P1.2 L --> N-Channel select, H --> P-channel select #define R_DRAIN_OUT 7 // bit P1.7 if P1.7 = H then NPN PNP #define RED_LED 0 // bit P1.0 #define GREEN_LED 6 // bit P1.6 //--------------------------------------------------------------- #define BIT(n) (1<<(n)) // this macro sets bit n
File: /media/j/texas/my msp430/g3tr/g3tr.c Pagina 2 di 5 enum FALSE,TRUE; //-------------------- global variables ------------------------ char RECOGNIZED; //--------------------------------------------------------------- void delay_ms(unsigned int d) unsigned int i,j; for(j=0;j<192;j++) for (i = 0; i<d; i++) nop(); //----------------------------------------------------------------------------------- void hardware_setup(void) WDTCTL = WDTPW WDTHOLD; // stop watchdog Timer BCSCTL1 = CALBC1_1MHZ; // Set range DCOCTL = CALDCO_1MHZ; // SMCLK = DCO = 1MHz PORT1_DIR = BIT(GREEN_LED) BIT(R_GATE_OUT) BIT(SOURCE_OUT) BIT( R_DRAIN_OUT); //configure as outputs PORT1_DIR &= ~BIT(BTN1) & ~BIT(BJT_MOSFET_IN) & ~BIT(DRAIN_IN); // configure as inputs tx_uart_setup(); //----------------------------------------------------------------------------------- void try_npn_nchannel(void) // Polarize the transistor under test like NPN or NCHANNEL PORT1 = BIT(R_DRAIN_OUT); // drain (collector)--> H PORT1 &= ~BIT(SOURCE_OUT); // source (emitter) --> L PORT1 = BIT(R_GATE_OUT); // gate (base) -------> H delay_ms( 20 ); // msec // may be npn or n-channel PORT1 &= ~ BIT(R_GATE_OUT); // gate (base) -------> L if(( P1IN & BIT(DRAIN_IN))!=0 ) //It is npn or n-channel // now it decides for npn-bjt or nchannel-mosfet PORT1 = BIT(R_GATE_OUT); // gate (base) ------ > H if(( P1IN & BIT(BJT_MOSFET_IN))!=0) sendstring(" N-CHANNEL MOSFET"); sendstring(" NPN BJT"); //end try_npn_nchannel //----------------------------------------------------------------------------------------------------- void try_pnp_pchannel(void) // Polarize the transistor under test like PNP or PCHANNEL
File: /media/j/texas/my msp430/g3tr/g3tr.c Pagina 3 di 5 PORT1 &= ~BIT(R_DRAIN_OUT); // drain (collector)---> L PORT1 = BIT(SOURCE_OUT); // source (emitter) ----> H PORT1 = BIT(R_GATE_OUT); // gate (base) -------> H // may be pnp or p-channel PORT1 &= ~ BIT(R_GATE_OUT); // gate (base) --> L //It is pnp or p-channel // now it decides for pnp-bjt or p-channel mosfet PORT1 &= ~ BIT(R_GATE_OUT); // gate (base) --> L if(( P1IN & BIT(BJT_MOSFET_IN))== 0) sendstring("p-channel MOSFET"); sendstring("pnp BJT"); //end try_pnp_pchannel() //---------------------------------------------------------------------------------------- void try_diode(void) //Polarize the DIODE under test PORT1 = BIT(R_DRAIN_OUT); // Anode ---> H PORT1 &= ~BIT(SOURCE_OUT); // Catode---> L //may be a DIODE; to verify, invert Polarization PORT1 &= ~BIT(R_DRAIN_OUT); // Anode ---> L PORT1 = BIT(SOURCE_OUT); // Catode---> H if(( P1IN & BIT(DRAIN_IN)) ==0) sendstring("diode [Anode on RED cable]"); //Polarize the DIODE under test in a different way PORT1 &= ~BIT(R_DRAIN_OUT); // Catode--> L PORT1 = BIT(SOURCE_OUT); // Anode---> H if(( P1IN & BIT(DRAIN_IN))!= 0) //may be a DIODE, so invert Polarization PORT1 = BIT(R_DRAIN_OUT); // Catode --> H PORT1 &= ~BIT(SOURCE_OUT); // Anode --> L sendstring("diode [Anode on BLACK cable]"); //end try_diode() //------------------------------------------------------------------------------------------ void try_short(void)
File: /media/j/texas/my msp430/g3tr/g3tr.c Pagina 4 di 5 PORT1 = BIT(R_DRAIN_OUT); PORT1 &= ~BIT(SOURCE_OUT); // H // L PORT1 &= ~BIT(R_DRAIN_OUT); PORT1 = BIT(SOURCE_OUT); sendstring("device SHORTED"); //end try_short(); // L // H //---------------------------------------------------------------------------------- void try_broken(void) PORT1 = BIT(R_DRAIN_OUT); // H PORT1 &= ~BIT(SOURCE_OUT); // L PORT1 &= ~BIT(R_DRAIN_OUT); // L PORT1 = BIT(SOURCE_OUT); // H sendstring("device BROKEN"); //end try_broken() //================================= M A I N ===================================== void main(void) char title[] ="\n\n\r Transistor Type Recognizer \n\n\r" ; char prompt[] ="\n\rg3tr> "; hardware_setup(); sendstring(title); sendstring(prompt); while (TRUE) if (RECOGNIZED) PORT1 &=~BIT(RED_LED); PORT1 = BIT(GREEN_LED); while (P1IN & BIT(BTN1)==0); // wait BTN1 pressed delay_ms(200); sendstring(prompt); PORT1 &=~BIT(GREEN_LED); PORT1 = BIT(RED_LED); if((p1in & BIT(BTN1))==0) // wait BTN1 pressed
File: /media/j/texas/my msp430/g3tr/g3tr.c Pagina 5 di 5 try_npn_nchannel(); try_pnp_pchannel(); try_diode(); //end while // end main try_short(); try_broken();