2016年7月27日 星期三

pic18f4620 adc 研究

Ref : 18f4620 spec

Ref : http://www.jgorasia.com/Files/UBWdemos/Documentation/periph-lib/AD%20Converter.htm



REGISTER 19-1: ADCON0: A/D CONTROL REGISTER 0
U-0 U-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0
— — CHS3 CHS2 CHS1 CHS0 GO/DONE ADON
bit 7 bit 0
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
-n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
bit 7-6 Unimplemented: Read as ‘0’
bit 5-2 CHS3:CHS0: Analog Channel Select bits
0000 = Channel 0 (AN0)
0001 = Channel 1 (AN1)
0010 = Channel 2 (AN2)
0011 = Channel 3 (AN3)
0100 = Channel 4 (AN4)
0101 = Channel 5 (AN5)(1,2)
0110 = Channel 6 (AN6)(1,2)
0111 = Channel 7 (AN7)(1,2)
1000 = Channel 8 (AN8)
1001 = Channel 9 (AN9)
1010 = Channel 10 (AN10)
1011 = Channel 11 (AN11)
1100 = Channel 12 (AN12)
1101 = Unimplemented)(2)
1110 = Unimplemented)(2)
1111 =



bit 1 GO/DONE: A/D Conversion Status bit
When ADON = 1:
1 = A/D conversion in progress
0 = A/D Idle
bit 0 ADON: A/D On bit
1 = A/D Converter module is enabled
0 = A/D Converter module is disabled


============================================================

REGISTER 19-2: ADCON1: A/D CONTROL REGISTER 1
U-0 U-0 R/W-0 R/W-0 R/W-0 R/W-q(1) R/W-q(1) R/W-q(1)
— — VCFG1 VCFG0 PCFG3 PCFG2 PCFG1 PCFG0
bit 7 bit 0


bit 5 VCFG1: Voltage Reference Configuration bit (VREF- source)
1 = VREF- (AN2)
0 = VSS
bit 4 VCFG0: Voltage Reference Configuration bit (VREF+ source)
1 = VREF+ (AN3)
0 = VDD







============================================================

ADCON2: A/D CONTROL REGISTER 2
R/W-0 U-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0
ADFM — ACQT2 ACQT1 ACQT0 ADCS2 ADCS1 ADCS0
bit 7 bit 0



bit 7 ADFM: A/D Result Format Select bit
1 = Right justified
0 = Left justified
bit 6 Unimplemented: Read as ‘0’
bit 5-3 ACQT2:ACQT0: A/D Acquisition Time Select bits
111 = 20 TAD
110 = 16 TAD
101 = 12 TAD
100 = 8 TAD
011 = 6 TAD
010 = 4 TAD
001 = 2 TAD
000 = 0 TAD(1)
bit 2-0 ADCS2:ADCS0: A/D Conversion Clock Select bits
111 = FRC (clock derived from A/D RC oscillator)(1)
110 = FOSC/64
101 = FOSC/16
100 = FOSC/4
011 = FRC (clock derived from A/D RC oscillator)(1)
010 = FOSC/32
001 = FOSC/8
000 = FOSC/2






The following steps should be followed to perform an A/D
conversion:

1. Configure the A/D module:
• Configure analog pins, voltage reference and
digital I/O (ADCON1)
• Select A/D input channel (ADCON0)
• Select A/D acquisition time (ADCON2)
• Select A/D conversion clock (ADCON2)
• Turn on A/D module (ADCON0)
2. Configure A/D interrupt (if desired):
• Clear ADIF bit
• Set ADIE bit
• Set GIE bit
3. Wait the required acquisition time (if required).
4. Start conversion:
• Set GO/DONE bit (ADCON0 register)

5. Wait for A/D conversion to complete, by either:
• Polling for the GO/DONE bit to be cleared
OR
• Waiting for the A/D interrupt
6. Read A/D Result registers (ADRESH:ADRESL);
clear bit ADIF, if required.
7. For next conversion, go to step 1 or step 2, as
required. The A/D conversion time per bit is
defined as TAD. A minimum wait of 2 TAD is
required before the next acquisition starts.


=======================================================


TAD vs. DEVICE OPERATING FREQUENCIES
AD Clock Source (TAD) Maximum Device Frequency
Operation ADCS2:ADCS0 PIC18F2X20/4X20 PIC18LF2X20/4X20(4)
2 TOSC 000 2.86 MHz 1.43 kHz
4 TOSC 100 5.71 MHz 2.86 MHz
8 TOSC 001 11.43 MHz 5.72 MHz
16 TOSC 101 22.86 MHz 11.43 MHz
32 TOSC 010 40.0 MHz 22.86 MHz
64 TOSC 110 40.0 MHz 22.86 MHz
RC(3) x11 1.00 MHz(1) 1.00 MHz(2)



=======================================================


 Introduction

The A/D peripheral is supported with the following functions:
TABLE:             A/D CONVERTER FUNCTIONS
Function
Description
BusyADC
Is A/D converter currently performing a conversion?
CloseADC
Disable the A/D converter.
ConvertADC
Start an A/D conversion.
OpenADC
Configure the A/D converter.
ReadADC
Read the results of an A/D conversion.
SetChanADC
Select A/D channel to be used.
SelChanConvADC
Select A/D channel to be used and start an A/D conversion.





Based on the different control registers, configuration bits and their positions in the control register, all PIC18 devices are divided into the following different versions. Wherever required, separate functions have been designed to support these versions, so before calling the LIB functions care has to be taken to know the version of the configured device and to call the appropriate function with correct number of arguments. For ADC_V11 user has to configure the I/O registers.
Below is the table to find the ADC version for the configured device:

TABLE: VERSION vs. DEVICES
Version name
Device number
ADC_V1
18C242, 18C252, 18C442, 18C452, 18F242, 18F252,
18F442, 18F452, 18F248 18F258, 18F448, 18F458,
18F2439, 18F2539, 18F4439, 18F4539
ADC_V2
18C601, 18C801, 18C658, 18C858, 18F6620, 18F6720,
18F8620, 18F8720, 18F6520, 18F8520
ADC_V3
18F1220, 18F1320
ADC_V4
18F1230, 18F1330
ADC_V5
18F2220, 18F2320, 18F4220, 18F4320, 18F2420,
18F2520, 18F4420, 18F4520, 18F2423, 18F2523,
18F4423, 18F4523, 18F2455, 18F2550, 18F4455,
18F4550, 18F2410, 18F2510, 18F2515, 18F2610,
18F4410, 18F4510, 18F4515, 18F4610, 18F2525,
18F2620, 18F4525, 18F4620, 18F6310, 18F6410
18F8310, 18F8410, 18F6390, 18F6490, 18F8390,
18F8490, 18F6527, 18F6622, 18F6627, 18F6722,
18F8527, 18F8622, 18F8627, 18F8722, 18F6585,
18F6680, 18F8585, 18F8680, 18F6525, 18F6621,
18F8525, 18F8621, 18F2450, 18F4450, 18F2480, 18F2580, 18F4480, 18F4580, 18F2585, 18F2680, 18F4585, 18F4680, 18F2682, 18F2685, 18F4682, 18F4685, 18F2221, 18F2321, 18F4221, 18F4321



   BusyADC

Function:
Is the A/D converter currently performing a conversion?
Include:
adc.h;
Prototype:
char BusyADC( void );
Remarks:
This function indicates if the A/D peripheral is in the process of converting a value.
Return Value:
1 if the A/D peripheral is performing a conversion.
0 if the A/D peripheral isn’t performing a conversion.
File Name:
adcbusy.c

2.2         CloseADC

Function:
Disable the A/D converter.
Include:
adc.h
Prototype:
void CloseADC( void );
Remarks:
This function disables the A/D converter and A/D interrupt mechanism.
File Name:
adcclose.c

2.3         ConvertADC

Function:
Starts the A/D conversion process.
Include:
adc.h
Prototype:
void ConvertADC( void );
Remarks:
This function starts an A/D conversion. The BusyADC() function or A/D interrupt may be used to detect completion of the conversion.
File Name:
adcconv.c

2.4         OpenADC


2.4.3        OpenADC (ADC_V3, 4, 5, 6)

For ADC_V3, ADC_V4, ADC_V5 and ADC_V6
Function:
Configure the A/D convertor.
Include:
adc.h
Prototype:
void OpenADC(unsigned char config,
             unsigned char config2 ,
             unsigned char portconfig);
Arguments:
Config
A bitmask that is created by performing either bitwise AND operation (‘&’) or bitwise OR operation (‘|’), configurable either way as shown in the example at the end of this file, with a value from each of the categories listed below. These values are defined in the file adc.h.

A/D clock source:
            ADC_FOSC_2    FOSC / 2
            ADC_FOSC_4    FOSC / 4
            ADC_FOSC_8    FOSC / 8
            ADC_FOSC_16  FOSC / 16
            ADC_FOSC_32  FOSC / 32
            ADC_FOSC_64  FOSC / 64
            ADC_FOSC_RC  Internal RC Oscillator

A/D result justification:
            ADC_RIGHT_JUST        Result in Least Significant bits
            ADC_LEFT_JUST          Result in Most Significant bits

A/D acquisition time select:
            ADC_0_TAD      0 Tad
            ADC_2_TAD      2 Tad
            ADC_4_TAD      4 Tad
            ADC_6_TAD      6 Tad
            ADC_8_TAD      8 Tad
            ADC_12_TAD    12 Tad
            ADC_16_TAD    16 Tad
            ADC_20_TAD    20 Tad

config2
A bitmask that is created by performing either bitwise AND operation (‘&’) or bitwise OR operation (‘|’), configurable either way as shown in the example at the end of this file, with a value from each of the categories listed below. These values are defined in the file adc.h.

Channel:
For ADC_V3:
            ADC_CH0          Channel 0
            ADC_CH1          Channel 1
            ADC_CH2          Channel 2
            ADC_CH3          Channel 3
            ADC_CH4          Channel 4
            ADC_CH5          Channel 5
            ADC_CH6          Channel 6
For ADC_V4:
            ADC_CH0          Channel 0
            ADC_CH1          Channel 1
            ADC_CH2          Channel 2
            ADC_CH3          Channel 3
For ADC_V5 and ADC_V6:
            ADC_CH0          Channel 0
            ADC_CH1          Channel 1
            ADC_CH2          Channel 2
            ADC_CH3          Channel 3
            ADC_CH4          Channel 4
            ADC_CH5          Channel 5
            ADC_CH6          Channel 6
            ADC_CH7          Channel 7
            ADC_CH8          Channel 8
            ADC_CH9          Channel 9
            ADC_CH10        Channel 10
            ADC_CH11        Channel 11
            ADC_CH12        Channel 12
            ADC_CH13        Channel 13
            ADC_CH14        Channel 14
            ADC_CH15        Channel 15

A/D Interrupts:
            ADC_INT_ON    Interrupts enabled
            ADC_INT_OFF  Interrupts disabled

A/D Vref+ and Vref- configuration:
    ADC_REF_VDD_VREFMINUS       VREF+ = VDD & VREF- = Ext.
    ADC_REF_VREFPLUS_VREFMINUS  VREF+ = Ext. & VREF- = Ext. 
    ADC_REF_VREFPLUS_VSS        VREF+ = Ext. & VREF- = VSS
    ADC_REF_VDD_VSS             VREF+ = VDD & VREF- = VSS

Portconfig
For ADC_V3:
The value of portconfig can be any value from 0 to 127, few are defined
below
            ADC_0ANA        All digital
            ADC_1ANA        analog:AN0                   
            ADC_2ANA        analog:AN0-AN1            
            ADC_3ANA        analog:AN0-AN2            
            ADC_4ANA        analog:AN0-AN3            
            ADC_5ANA        analog:AN0-AN4            
            ADC_6ANA        analog:AN0-AN5            
            ADC_7ANA        analog:AN0-AN6            
For ADC_V4:
The value of portconfig can be any value from 0 to 15, few are defined below
            ADC_0ANA        All digital
            ADC_1ANA        analog:AN0                   
            ADC_2ANA        analog:AN0-AN1            
            ADC_3ANA        analog:AN0-AN2            
            ADC_4ANA        analog:AN0-AN3            
For ADC_V5 and ADC_V6:
      ADC_0ANA        All digital
            ADC_1ANA        analog:AN0                    digital:AN1-AN15
            ADC_2ANA        analog:AN0-AN1             digital:AN2-AN15
            ADC_3ANA        analog:AN0-AN2             digital:AN3-AN15
            ADC_4ANA        analog:AN0-AN3             digital:AN4-AN15
            ADC_5ANA        analog:AN0-AN4             digital:AN5-AN15
            ADC_6ANA        analog:AN0-AN5             digital:AN6-AN15
            ADC_7ANA        analog:AN0-AN6             digital:AN7-AN15
            ADC_8ANA        analog:AN0-AN7             digital:AN8-AN15
            ADC_9ANA        analog:AN0-AN8             digital:AN9-AN15
            ADC_10ANA      analog:AN0-AN9             digital:AN10-AN15
            ADC_11ANA      analog:AN0-AN10           digital:AN11-AN15
            ADC_12ANA      analog:AN0-AN11           digital:AN12-AN15
            ADC_13ANA      analog:AN0-AN12           digital:AN13-AN15
            ADC_14ANA      analog:AN0-AN13           digital:AN14-AN15
            ADC_15ANA      All analog
Remarks:
This function resets the A/D-related registers to the POR state and then configures the clock, result format, voltage reference, port and channel.
File Name:
adcopen.c
Code Example:
With AND mask:
OpenADC( ADC_FOSC_32      &
         ADC_RIGHT_JUST   &
         ADC_12_TAD,
         ADC_CH0          &
                   ADC_REF_VDD_VSS  &
         ADC_INT_OFF, 12  );
With OR mask:
OpenADC( ADC_FOSC_32      |
         ADC_RIGHT_JUST   |
         ADC_12_TAD,
         ADC_CH0          |
         ADC_REF_VDD_VSS  |
         ADC_INT_OFF, 12  );



  ReadADC

Function:
Read the result of an A/D conversion.
Include:
adc.h
Prototype:
int ReadADC( void );
Remarks:
This function reads the 16-bit result of an A/D conversion.
Return Value:
This function returns the 16-bit signed result of the A/D conversion. Based on the configuration of the A/D converter (e.g., using the OpenADC() function), the result will be contained in the Least Significant or Most Significant bits of the 16-bit result.
File Name:
adcread.c




SetChanADC

This function not supports ADC_V7 and ADC_V7_1.

Function:
Select the channel used as input to the A/D converter.
Include:
adc.h
Prototype:
void SetChanADC( unsigned char channel );
Arguments:
Channel
One of the following values (defined in adc.h):
            ADC_CH0          Channel 0
            ADC_CH1          Channel 1
            ADC_CH2          Channel 2
            ADC_CH3          Channel 3
            ADC_CH4          Channel 4
            ADC_CH5          Channel 5
            ADC_CH6          Channel 6
            ADC_CH7          Channel 7
            ADC_CH8          Channel 8
            ADC_CH9          Channel 9
            ADC_CH10        Channel 10
            ADC_CH11        Channel 11
            ADC_CH12        Channel 12
            ADC_CH13        Channel 13
            ADC_CH14        Channel 14
            ADC_CH15        Channel 15
            ADC_CH_CTMU          Channel 13
            ADC_CH_VDDCORE  Channel 14
            ADC_CH_VBG            Channel 15
Remarks:
Selects the pin that will be used as input to the A/D converter.
File Name:
adcsetch.c
Code Example:
SetChanADC( ADC_CH0 );

2.7         SelChanConvADC

Function:
Select the channel used as input to the A/D converter  and starts the A/D conversion process.
Include:
adc.h
Prototype:
void SelChanConvADC( unsigned char channel );
Arguments:
Channel
One of the following values (defined in adc.h):
            ADC_CH0          Channel 0
            ADC_CH1          Channel 1
            ADC_CH2          Channel 2
            ADC_CH3          Channel 3
            ADC_CH4          Channel 4
            ADC_CH5          Channel 5
            ADC_CH6          Channel 6
            ADC_CH7          Channel 7
            ADC_CH8          Channel 8
            ADC_CH9          Channel 9
            ADC_CH10        Channel 10
            ADC_CH11        Channel 11
            ADC_CH12        Channel 12
      ADC_CH13        Channel 13
            ADC_CH14        Channel 14
            ADC_CH15        Channel 15
            ADC_CH_CTMU          Channel CTMU
            ADC_CH_VDDCORE  Channel VDDCore
            ADC_CH_VBG            Channel VBG
Remarks:
Selects the pin that will be used as input to the A/D converter. And starts an A/D conversion. The BusyADC() function or A/D interrupt may be used to detect completion of the conversion.
File Name:
adcselchcov.c
Code Example:
SelChanConvADC( ADC_CH0 );

2.8         Macro definitions

Macros
Description
ADC_INT_ENABLE()
Enables A/D interrupt i.e. sets PEIE and ADIE bits.
ADC_INT_DISABLE()
Disables the A/D interrupt.
ADC_SEVT_ENABLE()
Enables the Special Event Trigger bit, this macro is available for ADC_V4 only.
ADC_SEVT_DISABLE()
Disables the Special Event Trigger bit, this macro is available for ADC_V4 only.
ADC_CALIB()
Enables the A/D calibration bit, this macro is available forADC_V6 , ADC_V9, ADC_V11 and ADC_V12 only.
ADC_NO_CALIB()
Disables the A/D calibration bit, this macro is available forADC_V6 , ADC_V9, ADC_V11 and ADC_V12 only.
ADC_CH_GRA_AN0()
Selects the adc channel, this macro is available for ADC_V7 and ADC_V7_1 only.
ADC_CH_GRA_AN4()
Selects the adc channel, this macro is available for ADC_V7 and ADC_V7_1 only.
ADC_CH_GRB_AN1()
Selects the adc channel, this macro is available for ADC_V7 and ADC_V7_1 only.
ADC_CH_GRC_AN2()
Selects the adc channel, this macro is available for ADC_V7 and ADC_V7_1 only.
ADC_CH_GRD_AN3()
Selects the adc channel, this macro is available for ADC_V7 and ADC_V7_1 only.
ADC_CH_GRB_AN5()
Selects the adc channel, this macro is available for ADC_V7only.
ADC_CH_GRC_AN6()
Selects the adc channel, this macro is available for ADC_V7only.
ADC_CH_GRD_AN7()
Selects the adc channel, this macro is available for ADC_V7only.
ADC_CH_GRA_AN8()
Selects the adc channel, this macro is available for ADC_V7only.
ALL_CH_DIGITAL()
Selects the adc channel, this macro is available for ADC_V7only.

Example Use of the A/D Converter Routines with AND mask:
#include <p18cxxx.h>
#include <adc.h>
#include <delays.h>

int result;

void main( void )
{
  // configure A/D convertor
  OpenADC( ADC_FOSC_32      &
           ADC_RIGHT_JUST   &
           ADC_12_TAD,
           ADC_CH0          &
                     ADC_REF_VDD_VSS  &
           ADC_INT_OFF, ADC_CH10 );

  Delay10TCYx( 5 );     // Delay for 50TCY
  ConvertADC();         // Start conversion
  while( BusyADC() );   // Wait for completion
  result = ReadADC();   // Read result
  CloseADC();           // Disable A/D converter
}

Example Use of the A/D Converter Routines with OR mask:
#include <p18cxxx.h>
#define  USE_OR_MASKS
#include <adc.h>
#include <delays.h>

int result;

void main( void )
{
  // configure A/D convertor
  OpenADC( ADC_FOSC_32      |
         ADC_RIGHT_JUST   |
         ADC_12_TAD,
         ADC_CH0          |
                   ADC_REF_VDD_VSS  |
         ADC_INT_OFF, ADC_CH10 );
  Delay10TCYx( 5 );     // Delay for 50TCY
  ConvertADC();         // Start conversion
  while( BusyADC() );   // Wait for completion
  result = ReadADC();   // Read result
  CloseADC();           // Disable A/D converter
}


=======================================================



COMPARATOR MODULE
The analog comparator module contains two
comparators that can be configured in a variety of
ways. The inputs can be selected from the analog
inputs multiplexed with pins RA0 through RA5, as well
as the on-chip voltage reference (see Section 21.0
“Comparator Voltage Reference Module”). The digital
outputs (normal or inverted) are available at the pin
level and can also be read through the control register.
The CMCON register (Register 20-1) selects the
comparator input and output configuration. Block
diagrams of the various comparator configurations are
shown in Figure 20-1.
REGISTER 20-1: CMCON: COMPARATOR CONTROL REGISTER





2016年7月26日 星期二

pic delay function

Ref : http://jp.themes.pagesperso-orange.fr/pic/documentation/fonction_delay.htm


pic 18f4620 uart study

Ref :  https://www.youtube.com/watch?v=TbKW8vFe-Aw

Ref : http://www.dmi.unict.it/~santoro/teaching/lap1/slides/UART_MCU.pdf



























The following parameters must be set in the UART hardware:
transmission speed, in bps = Bit Per Second or baud

















  • 白色線為接收(RXD),接 Raspberry Pi 的傳送(TXD),8 號腳位。
  • 綠色線為傳送(TXD),接 Raspberry Pi 的接收(RXD),10 號腳位。


number of bits per character, usually 8
presence/absence of partity bit, usually absent
number of stop bits, usually 1
A setting 19200,8,N,1 means:
speed = 19200 bit-per-second;
bits = 8;
parity = None;
stop bits = 1.



UART in the PIC18F25K22
From the datasheet:
Two different UART
The TX line of the UART1 is shared with RC6
The RX line of the UART1 is shared with RC7
The TX line of the UART2 is shared with RB6
The RX line of the UART2 is shared with RB7
Basic registers per UARTx (“x” is the UART number):
TXSTAx, configuration of the transmitter
RCSTAx, configuration of the receiver
BAUDCONx, configuration of the baud rate (speed)
generator
SPBRGx, baud rate (speed) generator value



It is divisor driven from system clock frequency (FOSC).
It is controlled by the following bits/registers:
SPBRGHx:SPBRGx: the divisor value to be applied to
FOSC to obtain the desired baud rate
BAUDCONxbits.BRG16, a bit which indicates whether the
divisor value uses 8 or 16 bits
TXSTAxbits.BRGH, a bit which indicates if we are using a
high-speed baud date
A formula exists to compute the divisor value, but... Microchip
provides very usefull tables!



// setup UART
TRISCbits.TRISC6 = 0; // TX as output
TRISCbits.TRISC7 = 1; // RX as input
TXSTA1bits.SYNC = 0; // Async operation
TXSTA1bits.TX9 = 0; // No tx of 9th bit
TXSTA1bits.TXEN = 1 // Enable transmitter
RCSTA1bits.RX9 = 0; // No rx of 9th bit
RCSTA1bits.CREN = 1; // Enable receiver
RCSTA1bits.SPEN = 1; // Enable serial port
// Setting for 19200 BPS
BAUDCON1bits.BRG16 = 0; // Divisor at 8 bit
TXSTA1bits.BRGH = 0; // No high-speed baudrate
SPBRG1 = 51; // divisor value for 19200





Basic transmission
// wait the end of transmission
while (TXSTA1bits.TRMT == 0) {};
TXREG1 = new data; // start sending the new byte
... or, you can use directly the printf function, provided that you
implement a proper putch(char c) function, that is then called
by printf for each character to send.
Using printf
void putch(char c) {
// wait the end of transmission
while (TXSTA1bits.TRMT == 0) {};
TXREG1 = c; // send the new byte
}
...
printf("Hello world!!");



Reading a character
UART Char Reading
char read char(void)
{
while (PIR1bits.RC1IF == 0) { // wait for char
if (RCSTA1bits.OERR == 1) {
RCSTA1bits.OERR = 0; // clear overrun if it occurs
RCSTA1bits.CREN = 0;
RCSTA1bits.CREN = 1;
}
}
return RCREG1;




===================================================================
void oopenUART(void){


  /* Open the USART configured as 8N1, 2400 baud, in polled mode */

OpenUSART (USART_TX_INT_OFF &
USART_RX_INT_ON &
USART_ASYNCH_MODE &
USART_EIGHT_BIT &
USART_CONT_RX &
USART_BRGH_LOW,
_BAUD_9600);

//disable RX, we will enable it when INT0 Occur
 RCSTAbits.CREN = 0;

}




ULN2003A 達林頓陣列驅動器

Ref : http://bugworkshop.blogspot.tw/2011/08/diy-piculn2003a.html

ULN2003A 系列是一款高耐壓,大電流達林頓管驅動器 (Seven Darlington Arrays) 集成電路(IC),包含7個NPN達林頓管 (Darlington)。ULN2003A 具有必不可少的箝位二極體,用於電感性負載開關。ULN2003A 的應用包括繼電器、馬達、電燈和顯示器(LED)驅動等等。

▲ ULN2003A 集成電路
▲ ULN2003A 集成電路 16腳定義

ULN2003A 晶片內部做了一個消線圈反電動勢的箝位二極體。ULN2003A 的輸出端允許通過 IC 電流 200mA,飽和壓降 VCE 約 1V左右,耐壓 BVCEO 約為 36V。用戶輸出口的外接負載可根據以上參數估算。採用集電極開路輸出,輸出電流大,故可以直接驅動繼電器或固體繼電器 (SSR) 等外接控制器件,也可直接驅動低壓燈泡或 7個繼電器。

▲ ULN2003A 集成電路電路圖的箝位二極體
ULN2003A 的每一對達林頓都串聯一個2.7K 的基極電阻,在 5V 的工作電壓下它能與TTL 和 CMOS電路直接相連,可以直接處理原先需要標準邏輯緩衝器來處理的資料。ULN2003A 工作電壓高,工作電流大,灌電流可達 500mA,並且能夠在關態時承受 50V 的電壓,輸出還可以在高負載電流並行運行。

▲ ULN2003A 集成電路電路圖的達林頓管 (Darlington)
在 ULN2003A 輸入口輸入高電平時,輸出口為低電平,因為 ULN2003A 的輸出結構是集電極開路的,所以要在輸出端接一個上拉電阻,在輸入低電平的時候輸出才是高電平。在驅動負載的時候,電流是由電源通過負載灌入ULN2003A 的。

ULN2003A 的 COM腳主要有兩種用途:(可懸空)1. 試驗用----接地:假如它的輸出端都接發光二極體,那麼,只要將 COM 端接地,則所有的發光二極體都將亮起,否則,可能是二極體壞或其他什麼地方壞了。這對檢修是很有利的。

▲ ULN2003A 輸入低電平,LED 熄滅。
▲ ULN2003A 輸入高電平時,LED 亮光。
 2. 保護用----接電源正:假如這個器件是接繼電器或針式打印頭,因為電感的作用,會在開關過程中產生低於地電位和高於電源電位的反電動勢,這樣,很容易擊穿器件。

  • 為了防止這種現象的發生,可將 COM 端接到電源正,來削減衝擊電壓低到二極體壓降加電源電壓的幅度----可以使得內部的三極管受到最小的正電壓衝擊。
  • 至於達林頓關斷時產生的負電壓我們不必管,因為器件內部就有二極體並接到地----專門用來削減衝擊電壓至電源地減去一個二極體正向壓降----可以使得內部的三極管受到最小的反偏電壓衝擊。
▲ ULN2003A 輸入接至步進馬達的四組線圈。