Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

reading output of CO detector module with pic16f690 micrcontroller

Status
Not open for further replies.

cjt

New Member
reading output of CO detector module with pic16f690 micrcontroller

im designing an carbon monoxide detector for my project. I am a new user to the pic microcontroller.

I am programming in C.

I have an CO detector module in place. I am trying to take the alarm signal from that and get the microcontroller to give me an output (like a LED lighting up).


hardware connections:

1) RC2 is connected to the CO detector's heater - needed to drive the CO detector
1) RC1 is connected to the alarm pin of the CO detector

I want to be able to light up the RCO LED when the alarm is triggered on the CO detector. I have used the RC3 LED as an indicator of when the CO module is in its purge phase.

here is my code
/*********************************************************
Configuration of PicKit
*********************************************************/

#include <pic.h> // Include HITECH CC header file


__CONFIG (INTIO & WDTDIS & PWRTDIS & MCLRDIS & BORDIS
& UNPROTECT & IESODIS & FCMDIS );
//Internal clock, Watchdog off, MCLR off, Code Unprotected

/*********************************************************
Est. Variables to be used in Program
*********************************************************/

int alarm = 0;
// Create A/D storage value and set it to 0

int index = 0;
// Est. counter index

int index2 =0;

void pause( unsigned short usvalue );
// Est. pause routine function

void msecbase( void );
// Est. millisecond base function


/*********************************************************
Program
*********************************************************/

main()
{
ANSEL = 0; // No Analog inputs yet
CM1CON0 = 0; // Initialize Comparator 1 off
CM2CON0 = 0; // Initialize Comparator 2 off

PORTC = 0x00; // Clear PortC port
TRISC = 0x02; // RC1 I/O input, rest of PortC I/O outputs


while(1==1) // Loop forever
{

RC2 = 1; // Set HSW to 5 volts (heater voltage)

// The following while loop controls the minute long purging cycle of the Carbon Monoxide Detector

index = 60;
// Set index to 60 - will serve as a timer for the purging cycle
while (index > 0)
// Loop will run as long as index is greater than zero
{
RC2 = 1;
if (RC1 == 1)
{
RC0 = 1;
pause(1000); // Delay for 1 sec
}
if (RC1 == 0)
{
RC0 =0;
pause(1000);
}
index = index -1;

RC3 = 1;
// Turn on RC3 LED during purging cycle
}

// The following while loop controls the minute and a half long detecting cycle of the Carbon Monoxide Detector


index2 = 78;
// Set index2 to 78 - will serve as a timer for the purging cycle
RC3 = 0;
// Turn off RC3 LED
while(index2 > 0)
{
index = 56;
// Set index to 56 - will serve as a timer for the purging cycle
while(index > 0)
{

RC2 = 1;
// Turns HSW voltage on (5 V)
pause(15);
// Calls on the pause function for a 15 millisecond delay
RC2 = 0;
// Turns HSW voltage off (0 V)
pause(3);
// Calls on the pause function for a 15 millisecond delay
// The turning on and off of the HSW voltage serves to a pulse width modulate the voltage and obtain a voltage of 1.4 V for the detector phase
index = index -1;

if (RC1 == 1)
{
RC0 = 1;
}

if (RC1 == 0)
{
RC0 = 0;
}
}
index2 = index2 -1;
}
} // End while
} // End main

The Following is the Code for the pause function and msecbase

//*******************************************************
//pause - multiple millisecond delay routine
//*******************************************************
#include <pic.h> // Include HITECH CC header file

void msecbase( void ); //Establish millisecond base function

void pause( unsigned short usvalue )

{
unsigned short x;

for (x=0; x<=usvalue; x++) //Loop through a delay equal to usvalue
{ // in milliseconds.
msecbase(); //Jump to millisec delay routine
}
}


/********************************************************
* msecbase - 1 msec pause routine *
* The Internal oscillator is set to 4 Mhz and the *
* internal instruction clock is 1/4 of the oscillator. *
* This makes the internal instruction clock 1 Mhz or *
* 1 usec per clock pulse. *
* Using the 1:4 prescaler on the clock input to Timer0 *
* slows the Timer0 count increment to 1 count/4 usec. *
* Therefore 250 counts of the Timer0 would make a one *
* millisecond delay (250 * 4 usec). But there are other *
* instructions in the delay loop so using the MPLAB *
* stopwatch we find that we need Timer0 to overflow at *
* 243 clock ticks. Preset Timer0 to 13 (0D hex) to make *
* Timer0 overflow at 243 clock ticks (256-13 = 243). *
* This results in a 1.001 millisecond delay which is *
* close enough. *
*********************************************************/
#include <pic.h> // Include HITECH CC header file

void msecbase(void)
{
OPTION = 0b00000001; //Set prescaler to TMRO 1:4
TMR0 = 0xD; //Preset TMRO to overflow on 250 counts
while(!T0IF); //Stay until TMRO overflow flag equals 1
T0IF = 0; //Clear the TMR0 overflow flag
}


Please help me. i dont know why I cant get the RC0 led to turn on when the alarm conditions of the CO detector module are on.
 
My guess would be that the heater needs more than 20mA to heat up. Do you have a link to the sensor.

Mike.
 
He says the alarm condition is "on" so it must be something in his code.
Secondly why not just drive the heater straight from V+?
I guess if you want to save battery power or something.
He didn't say where he would be using it though.
 
I didnt drive the heater from v+ because the CO module has a four pin input into the micro controller. There is a v+ pin, ground pin , heater pin, and alarm pin. I'm using a parallax CO Gas Sensor Module as my detection device.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top