Continue to Site

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.

[PIC] DAC output destroyed (PIC16F1783)

Status
Not open for further replies.

Schulerbible

Newbie level 4
Newbie level 4
Joined
May 9, 2014
Messages
6
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Visit site
Activity points
52
Hi guys,

I got a pair of PIC16F1783 microcontrollers (programmed in MPLAB). The PIC 16F1783 has a 8-bit DAC with two outputs. I implemented a PI loop for a temperature regulation. The output of the DAC is connected to the base of a 2N6488 (NPN) transistor that switches a 12V source which drives an electric heater on (255) and off (0). This was just a quick test. Later I would like to use the 8 bit resolution to limit the current through a transistor.

All worked fine so far but at some point the DAC output did not worked abymore. So, I switched to the second output and here I experienced the same thing. During the last days I grilled 3 of 4 outputs and I still don't have a solution for that.

What I think could have happened:
During programming and debugging I measured the output voltage with a multimeter and maybe I touched the probe (multimeter needle) with my fingers which could have result in a static shock at the DAC pin. When I use the DAC outputs as I/0 pin then they are dead as well. So, something happened of I am not aware.

I don't use any buffer circuit since I have no idea how to set this up. It would be good to find a quick and easy solution to prevent this problems in future.

Thanks
Tobias
 

Is there a resistor between DAC out and Base of BJT? Is BJT also dying? What is the max emitter-base voltage of BJT? If max EB V is < 5V then maybe transistor EB is shorting and in turn shorting DAC out to GND.
 

Is there a resistor between DAC out and Base of BJT? Is BJT also dying? What is the max emitter-base voltage of BJT? If max EB V is < 5V then maybe transistor EB is shorting and in turn shorting DAC out to GND.

Good question ... I have not checked BJT yet. But anyway if I remove the transistor and just measure the plain output with a multimeter there is no voltage output anymore.

And there is no resistor between DAC and Base since Veb is given as 5V. How may I protect the shorting, using a Zener diode?

Thanks for your comments!

Cheers
Tobias
 

Hi

VEB is the reverse voltage. Look for VBE.

In general you almost always need a current limiting device at the base.

Klaus
 

I would agree with both Milan.rajik and KlausST, driving the transistor directly from the output of the DAC is most likely the root of the failure.

A more prudent design would be to utilize an opamp in a voltage follower/buffer configuration along with some method of current limiting.

Reference: **broken link removed**, Section: 19.3 DAC Voltage Reference Output, Page: 169 and 170
19.3 DAC Voltage Reference Output

The DAC voltage can be output to the DACOUT1 and
DACOUT2 pins by setting the respective DACOE1 and
DACOE2 pins of the DACCON0 register. Selecting the
DAC reference voltage for output on either DACOUTX
pin automatically overrides the digital output buffer and
digital input threshold detector functions of that pin.
Reading the DACOUTX pin when it has been
configured for DAC reference voltage output will
always return a ‘0’.

Due to the limited current drive capability, a buffer must
be used on the DAC voltage reference output for
external connections to either DACOUTx pin.
Figure 19-2 shows an example buffering technique.

Figure 19-2:



BigDog
 

VEB is the reverse voltage. Look for VBE.

My mistake. I meant Base to Emitter voltage.

For general purpose BJT you need 0.6 to 0.8V to forward bias it. So put a 820E to 1k between DAC out and base of BJT.

(DACOUT - 0.8) / 5 mA = R
 

Hi

VEB is the reverse voltage. Look for VBE.

In general you almost always need a current limiting device at the base.

Klaus


I have no idea if this is right but it says: VBE = 1.3V at 5Adc and Vce=4V. However I do have Vce = 12V (if I am right).


Kind regards,

Tobias
 

A current limiting resistor alone will most likely not solve the problem.

Although the specifications of the DAC are not well documented, its output impedance appears to be relatively low, utilizing only a current limiting resister will more than likely generate additional loading issues.

Implementing a voltage follower/buffer is not difficult, it is as simple as shown in figure 19-2 that I previously posted.

I would suggest posting a detailed schematic of the current design, along with an equally detailed description of the task you are attempting to accomplish.

BigDog
 

I would suggest posting a detailed schematic of the current design, along with an equally detailed description of the task you are attempting to accomplish.

BigDog

Here it is, I guess you wanna slap me now :)

The purpose of the whole thing is to run a PI loop to temperature stabilize a spectrometer. I am using a pair of 10K thermistors
in Wheatstone arrangement and the DAC controls a transistor that switches a 12V source. Yes you can do that with a PWM as well but this is just a previous project I actually plan to use the 8-bit output later.


And here is the code:
Code:
//================================================================
// Spectrograph temperature regulation (PI feedback controller)
// File:   newfile.c
// Author: Tobias Feger
//
// Created on 3. May 2014
//===============================================================

//****************************** include/pragma and define:
#include <xc.h>
#include <pic.h>
#include <plib/adc.h>
#include <plib/delays.h>
#include <stdlib.h>
#include <htc.h>
#include <stdio.h>
#include <math.h>

#pragma config LVP = OFF
#pragma config MCLRE = OFF         // MCLR Pin Function Select (MCLR/VPP pin function is MCLR)
#pragma config FOSC = INTOSC    // (ECH, External Clock, High Power Mode (4-32 MHz); device clock supplied to CLKIN pin)
#pragma config WDTE = OFF       // Watchdog Timer Enable (WDT enabled)
#pragma config PWRTE = ON       // Power-up Timer Enable (PWRT disabled), Sprut: ON!
#pragma config CP = OFF         // Flash Program Memory Code Protection (Program memory code protection is disabled)
#pragma config BOREN = OFF      // Brown-out Reset Enable (Brown-out Reset enabled)

#define _XTAL_FREQ 32000000

//****************************** Variables:
unsigned int  adc_AN0 = 0;   // channel 1
unsigned int  adc_AN1 = 0;   // channel 2
unsigned int  adc_AN4 = 0;   // channel 4
unsigned int  adc_AN5 = 0;   // channel 5

double AN0_voltage;
double AN1_voltage;

float Setpoint=24.2;        //Setpoint temperature
float Error=0.0;
float Integral=0.0;
float kP=5.0;                //P-gain
float kI=0.1;                //I-gain

float R0=10.0;         //Thermistor 10K at 25deg
float T0=298.0;
float Test=0.0;
double diff_voltage; 
float dR;
float R2;
float sleep_1=0.0;
float sleep_2=0.0;

double T1;
double T_bridge;

int myint1;
int myint2;
//****************************** Delay function (brauchmer net):
void delay(int ms)
{
    while(ms-- > 0){__delay_ms(1);}
}

//********** Initialize the DAC converter:
// read: http://electronics.stackexchange.com/questions/107756/pic12-dac-has-no-output
// DACOUT1 = RA2, DACREF = RA3 (5V)
void init_dac(void)
{
    ANSELA=0b00000000;     //all pins to digital
    PORTA=0x00;   
    DACCON0=0b10100000;    //Make RA2 as output!  
}

//********** Initialize the ADC converter:
// ADCREF = RA3 (5V)
void init_adc(void)
{
    PORTA=0x00;     
    TRISA=0b11111111;     //Port A is all inputs.   
    ANSELA=0b00000011;     //Pin RA0 and RA1 are analog inputs
    ANSELA=0;
    ADCON0=0b00000001;     //all inputs are digital except of AN0 
    ADCON1=0b10010000; 
    ADCON2=0b00001111; 
}

//********** Preform the AD conversion:
unsigned int GetADCvalue(int channel)
{
    if(channel==0){ADCON0=0b00000001;}
    if(channel==1){ADCON0=0b00000101;}
    if(channel==3){ADCON0=0b00001101;}
    //if(channel==4){ADCON0=0b00010001;}

    GO_nDONE = 1;                      //start the ADC conversion
    __delay_ms(5);
    while(GO_nDONE);                 //wait for the conversion to finish
    return ((ADRESH<<8)+ADRESL);    //return the result
}

//********** Heater control:
float GetDrive(float Test)
{
    sleep_1=500.0*Test;    
    sleep_2=500.0*(1.0-Test);
    myint1=sleep_1;
    myint2=sleep_2;
       
    if(Test==0.0){DACCON1=0;}
    else{DACCON1=255;} 
    delay(myint1);    
 
     if(Test==1.0){DACCON1=255;}    
    else{DACCON1=0;}
    delay(myint2);        
}

//=======================================================================================
void main(void){
    PORTB=0x00;
    TRISB=0x00;  
    OSCCON=0b11111000; //Setup internal oscillator 32MHz
    init_adc();    //initialise ADC
    init_dac();    //initialise DAC
 
    while(1)
        {
        adc_AN0=GetADCvalue(0);                 // ADC channel 1
        AN0_voltage=(adc_AN0)/4096.0*5.0;
        adc_AN1=GetADCvalue(1);                 // ADC channel 2
        AN1_voltage=(adc_AN1)/4096.0*5.0;

        
        diff_voltage=AN1_voltage-AN0_voltage;
        dR=2.0*R0*diff_voltage/(5.0-diff_voltage);
        R2=R0+dR;
        
        T_bridge=1.0/T0+log(R2/R0)/3920.0;           
        T1=(1.0/T_bridge)-273.0;

        Error=T1-Setpoint;
        Integral=Integral+Error;
        if(Integral>0.5/kI){Integral=0.5/kI;}             //+5 upper boundary
        else if(Integral<-0.5/kI){Integral=-0.5/kI;}    //-5 lower boundary
            
        Test=0.5-(Error*kP)-(Integral*kI);
           if(Test<0.0){Test=0.0;}
        if(Test>1.0){Test=1.0;} 
        GetDrive(Test);
        }//end while(1)

}//end main
 

Attachments

  • drawing.jpg
    drawing.jpg
    12.3 KB · Views: 76

Gulp!

It isn't the software, it's the hardware that's wrong. You clamped the 'weak' output of the DAC to Vbe of the transistor, as far as the PIC is concerned the base to emitter looks like a forward biased diode so when it had enough voltage across it to start conduction it behaved almost as a short circuit between the DAC output and ground. A current limiting resistor will offer some protection to the DAC but as it has such low output current capability, the buffer amplifier suggested by the data sheet and Bigdogguru would be a much better solution.
 

Gulp!

It isn't the software, it's the hardware that's wrong. You clamped the 'weak' output of the DAC to Vbe of the transistor, as far as the PIC is concerned the base to emitter looks like a forward biased diode so when it had enough voltage across it to start conduction it behaved almost as a short circuit between the DAC output and ground. A current limiting resistor will offer some protection to the DAC but as it has such low output current capability, the buffer amplifier suggested by the data sheet and Bigdogguru would be a much better solution.

I completely agree with what you wrote. However due to my lack of knowledge in buffer circuits and the nice diagram given in the PIC datasheet which doesn't give any specifications I am completely lost. I would highly appreciate if somebody could give me an advice which parts I should use to set up such a buffer circuit.

Thanks in advance!

Cheers Tobias
 

Refer to "Electronic Devices and Circuit Theory 10 / 11th ed by Boylestead and Nashelsky" and "Introductory Electronic Devices and Circuits 7th ed by Robert T Paynter"
 

Hi,

here´s a schematic for a clean control of current.
All (almost) the power is dissipated with the BJT/MOSFET,
I´d prefer a MOSFET.
schem.PNG
The DAC sees a high ohmic load. I´t wont be fried anymore

Good luck.
Klaus

edit1: schem attached
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top