Schulerbible
Newbie level 4
- Joined
- May 9, 2014
- Messages
- 6
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1
- Activity points
- 52
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.
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.
VEB is the reverse voltage. Look for VBE.
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 suggest posting a detailed schematic of the current design, along with an equally detailed description of the task you are attempting to accomplish.
BigDog
//================================================================
// 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
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.
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?