Mithun_K_Das
Advanced Member level 3
- Joined
- Apr 24, 2010
- Messages
- 899
- Helped
- 24
- Reputation
- 48
- Reaction score
- 26
- Trophy points
- 1,318
- Location
- Dhaka, Bangladesh, Bangladesh
- Activity points
- 8,254
You want to convert the Digital signal with ADC???Problem # 2: If I use One Digital input and others Analog, then the PIC16F877A will measure/calculate either the Analog one or the Digital one. Can't calculate both although both measurement have different time of measurement. Have 3000ms gap between two measurement.
hi Mithun_K_Das
Are you using DHT11, the temperature & humidity sensor?
So you are processing one data with the PICs' analog port and another data with the DHT11?
If i get it correctly, it has a bidirectional single wire communication. Sometimes, even clock synchronized bidirectional serial communication protocols give you a headache if not properly synchronized, I had the same problem once with a bridge transducer.
May be you are missing some bits of the received data for being wrongly shifted.
Sudden loss of precision may be due to the left/right shifting of the ADC result being set incorrectly. Try applying a gradually increasing voltage (from a potentiometer for example) and see if it gives a linear count then after 255 suddenly jumps to a much different figure. If it does, try checking the justification of the high ADC result.
Brian.
Sudden loss of precision may be due to the left/right shifting of the ADC result being set incorrectly. Try applying a gradually increasing voltage (from a potentiometer for example) and see if it gives a linear count then after 255 suddenly jumps to a much different figure. If it does, try checking the justification of the high ADC result.
Brian.
sbit Data at RA1_bit;
sbit DataDir at TRISA1_bit;
char message2[] = "H: ";
char message3[] = "H: ";
unsigned short TOUT = 0, CheckSum, i;
unsigned int value;
unsigned char ch;
unsigned short row, position;
unsigned int ax,bx,cx,dx;
unsigned int ax1,bx1,cx1,dx1;
unsigned long button_value;
unsigned long button_value2;
unsigned long Recent_Temp_Value;
unsigned int humidity;
long tlong;
float temp;
float average;
unsigned int j,adc_rd0;
unsigned int sample[3];
unsigned int T_Byte1, T_Byte2, RH_Byte1, RH_Byte2;
void StartSignal()
{
DataDir = 0; // Data port is output
Data = 0;
Delay_ms(25);
Data = 1;
Delay_us(30);
DataDir = 1; // Data port is input
}
unsigned short CheckResponse()
{
TOUT = 0;
TMR2 = 0;
T2CON.TMR2ON = 1; // start timer
while(!Data && !TOUT);
if (TOUT) return 0;
else
{
TMR2 = 0;
while(Data && !TOUT);
if (TOUT) return 0;
else
{
T2CON.TMR2ON = 0;
return 1;
}
}
}
unsigned short ReadByte()
{
unsigned short num = 0, t;
DataDir = 1;
for (i=0; i<8; i++)
{
while(!Data);
Delay_us(40);
if(Data) num |= 1<<(7-i);
while(Data);
}
return num;
}
void interrupt()
{
if(PIR1.TMR2IF)
{
TOUT = 1;
T2CON.TMR2ON = 0; // stop timer
PIR1.TMR2IF = 0; // Clear TMR0 interrupt flag
}
}
// port initialization
TRISB = 0b00000000;
PORTB = 0;
TRISA = 0b00100011;
TRISC = 0x10; // RC4 in all out
PORTC = 0x00;
TRISD = 0x0C; // D2 & D3 inputs all out
PORTD = 0x00;
CMCON = 7;// comparator off
ADCON1 = 0b00001110;// AN selletion
INTCON.GIE = 1; //Enable global interrupt
INTCON.PEIE = 1; //Enable peripheral interrupt
// Configure Timer2 module
PIE1.TMR2IE = 1; // Enable Timer2 interrupt
T2CON = 0; // Prescaler 1:1, and Timer2 is off initially
PIR1.TMR2IF =0; // Clear TMR INT Flag bit
TMR2 = 0;
Lcd_Init();
Lcd_Cmd(_Lcd_Clear);
Lcd_Cmd(_LCD_CURSOR_OFF);
while(1)
{
DHT11_Data();
Delay_ms(500);
Thermal_Data();
Delay_ms(500);
}// while(1)
/*******************************************************************************/
/***************************** DHT11_Data **************************************/
/*******************************************************************************/
void DHT11_Data(void)
{
unsigned short check;
//PIE1.TMR2IE = 1; // Enable Timer2 interrupt
//ADCON1 = 0b10000111; // all digital selected
StartSignal();
check = CheckResponse();
if (!check)
{
Lcd_Cmd(_Lcd_Clear);
Lcd_Out(1, 1, "No response");
Lcd_Out(2, 1, "from the sensor");
}
else
{
RH_Byte1 = ReadByte();
RH_Byte2 = ReadByte();
T_Byte1 = ReadByte();
T_Byte2 = ReadByte();
CheckSum = ReadByte();
// Check for error in Data reception
if (CheckSum == ((RH_Byte1 + RH_Byte2 + T_Byte1 + T_Byte2) & 0xFF))
{
value = RH_Byte1;
message2[0] = RH_Byte1/10 + 48;
message2[1] = RH_Byte1%10 + 48;
Lcd_Out(1,14, message2);
Lcd_Out(1,16,"%");
}
else
{
Lcd_Cmd(_Lcd_Clear);
Lcd_Out(1, 1, "Checksum Error!");
Lcd_Out(2, 1, "Trying Again...");
}
}
//ADCON1 = 0x00;// all analog selected
}
/*******************************************************************************/
/***************************** Thermal_Data *********************************/
/*******************************************************************************/
void Thermal_Data(void)
{
Delay_ms(50);
//ADCON1 = 0x00;// all analog selected
ADCON0=0b11000001;// Channel 1 selected with internal clock speed
for(j=0; j<3; j++)
{
adc_rd0 = ADC_Read(0);
sample[j] = adc_rd0;
Delay_ms(200);
}
average = 0;
for(j=0;j<3;j++)
{
average += sample[j];
}
average /= 3;
average = ((1023 /average )-1);
average = 10000/average; // get the resitror value
temp = average/10000; // R/Ro
temp = log(temp); // temp = log(R/Ro)
temp /= 3950; // 1/B
temp += 1.0/(25.00 + 273.15);
temp = 1.00/temp;
temp = ((temp-273.15)*1.8)+32.00; // converting K to F.
tlong = temp*100;
Recent_Temp_Value = temp*100;
row = 1;
position = 3;
Lcd_Out(1,1,"T:");
Display_Temp();
ax = EEPROM_Read(0);
bx = EEPROM_Read(1);
cx = EEPROM_Read(2);
dx = EEPROM_Read(3);
button_value = dx*1000 + cx*100 + bx*10 + ax;
row = 2;
position = 3;
tlong = button_value;
Display_Temp();
Lcd_Out(2,1,"S:");
//ADCON1 = 0b10000111; // all digital selected
}
Are you changing the ADC configuration frequently in the code?
You want to convert the Digital signal with ADC???
post your code, please
Hi,
Have used the DHT11 sensors ( though not that accurate) along side analogue thermistors and other digital sensors on the same chip without any problem.
Your timing gaps are fine and you only need a 2 second gap between reads of the DHT11
You do not say exactly what is not working in the ADC ? incorrect result or nothing at all ?
Would suspect you have somehow got your ports or even registers mixed up, have you configured them correctly.
Are both sensors boards on the same +5v rail as the Pic ?
Also would avoid using RB6 and RB7, that means you would have to isolate the sensors for programming and it will stop you using the debugger function if you have a Pickit programmer ? if so have you tried running Debugger to see whats happening ?
If still stuck show your code and circuit so with can see whats happening.
Hi,
Can u give the exact pin connections on PIC. At what pins u have connected the thermistor and the humidity sensor? And tell the nature of t signal fed to PIC by each sensors...
Thanks for your reply first. Yes, the ADC is showing wrong result. and its varying with time without any voltage change at the pin. And the both sensors are connected at the same +5V source.
I don't know why you are suggesting to avoid RB6 & RB7. I'm using QL programmer. I didn't see the debugger result yet. Actually I'm still confused. Because if I run only thermistor, its ok. If I run only DHT11, its ok. But if I run both its not ok.
Still don't know where is the problem.
Hi,
The point about RB6 and RB7 only applies if your are using an In Circuit Serial Pprogrammer.
Again if you are using a hardware debugger then RB6 and RB7 must be dedicated to the Debugger.
Software apart, I would suspect you have a +5v problem in that the adc or dht are taking too much current when both are connected.
Without seeing your circuit diagram it is hard to say what the cause is.
Are you using Vref to power the thermistor or +5v ?
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?