UVTron to BrainStem Example
Last Modified: 2009-11-04
find:

basket

Acroname Robotics PDF webpage version UVTron to BrainStem Example PDF

Related
Products

Product image for Brainstem GP 1.0 Module
Brainstem GP 1.0 Module
Product image for 2600mAh AA NiMH Battery
2600mAh AA NiMH Battery
Product image for UVTron Flame Detector Package
UVTron Flame Detector Package
Product image for 4X AA Battery Pack w/Connector
4X AA Battery Pack w/Connector

Contents

Interface setup for using the UVTron with the BrainStem.

Introduction

In this example, the Hamamatsu UVTron detector provides a one-bit flame detection input for a BrainStem GP 2.0.  A reflex updates a counter each time it detects a pulse from the UVTron.  A small subroutine written in TEA returns the pulse count in a desired interval.  A main TEA routine continuously takes readings and prints the results to the BrainStem GP 2.0 Console. 

Circuit Schematic

This circuit uses a UVTron Driver Board that has had its 5V regulator bypassed.  The BrainStem GP 2.0 supplies regulated 5V power to the UVTron Driver Board.  Signal output from the UVTron is wired into the digital pin 1 on the BrainStem.  What digital pin is being used will need to be known when developing the counting reflex and the TEA file. 

Wiring diagram for the UVTron to the BrainStem.

Source Code - Reflex for Counting UVTron Pulses

A UVTron pulse counting reflex is used to tally the number of pulses that occur from the UVTron detector.  The following is a compiled reflex routine that can be loaded onto a BrainStem controller.  The reflex routine is hard-coded to use digital I/O pin 1 for the UVTron input.  It is possible to change the pin, but this requires changing the reflex file.  For more information on this type of reflex, see the Digital Polling example in the Reflexes section of the online BrainStem Reference.  It describes a reflexive routine similar to the one that is used here. 

The following is a reflex leaf file that contains the description of the UVTron pulse counting reflex. 

/* uvrflx.leaf */ #include <aCmd.tea> /* Use this when using a GP 2.0 board */ #include <aGP2Reflexes.tea> /* Uncomment when using a GP 1.0 board */ // #include <aGPReflexes.tea> /* assume the BrainStem has address 2 */ #define MODULE 2 #define DIOPIN 1 #define COUNTER0 0 /* message ids */ #define mCOUNT 0 #define mRESET 1 module[MODULE] { /************* REFLEX COMMANDS *************/ message[mCOUNT] { MODULE, cmdCTR_CT, COUNTER0, 1 } message[mRESET] { MODULE, cmdDIG_RST, DIOPIN } /************* REFLEX VECTORS *************/ /* GP 2.0 digital pin 1 transition reflex */ vector[aGP_RFX_DTRANS_1] { mCOUNT, mRESET } }

To compile the reflex, the file must first be placed into the aUser BrainStem directory.  Then enter batch "uv_ex.bag" at the Console prompt. 

brainstem> leaf uvrflx.leaf LEAF Compiler (Little Embedded Application Fragments) leaf version 1.0 Copyright 1994-2009, Acroname Inc.

Then load the resulting commands onto the BrainStem by using the "batch" command from within the aConsole application. 

brainstem > batch "uvrflx.bag"

Source Code - TEA File

The aUVTron_Read_Int routine takes a sampling interval parameter in 0.1ms units.  It resets an internal counter, then waits for the sampling interval to expire.  Then it returns the number of UVTron pulses during that interval.  The main program has a sampling interval of 1 second. 

Try loading the reflex and TEA program.  Run the program and observe the output.  The Console display should give readings of 0 every second.  Light a match 8-10 inches away from the sensor.  With a stock UVTron, The Console display should have readings of 4 to 6 pulses after each sampling interval. 

It is possible to control the output pulse width and background cancellation on the UVTron Driver Board by making some minor modifications to the board.  After such a procedure, it will be necessary to try a different sampling interval to get the best results. 

/* uv_ex.tea */ /* IOPort definitions and display routines */ #include <aCore.tea> #include <aPrint.tea> #include <aDig.tea> #define uvtronCTR 0 void aUVTron_Setup() { /* Setting the ADIG_POLLENA bit triggers the digital transition */ /* reflex. This is defined in the uvrfx.leaf file */ aDig_Config(1, ADIG_INPUT | ADIG_POLLENA | ADIG_POLLHI); } /* aUVTron_Setup */ /* * * * * * * * * * * * * * * * * * * * * * * */ int aUVTron_Read_Int(int nTime) { int val=0; /* Set the counter to zero */ aCore_Outporti(aPortRflxCtr + uvtronCTR, 0); /* Wait and count the pulses */ aCore_Sleep(nTime); /* Read from the reflex counter */ val = aCore_Inporti(aPortRflxCtr + uvtronCTR); return val; } /* aUVTron_Read_Int */ /* * * * * * * * * * * * * * * * * * * * * * * */ void main() { int num = 0; int reading; /* call setup once to configure the I/O */ aUVTron_Setup(); /* loop forever showing the readings */ while (1) { /* take a reading (number of pulses in one * second) */ reading = aUVTron_Read_Int(10000); /* build up the display line */ aPrint_String("Pulses in Interval "); aPrint_IntDec(num++); aPrint_String(" = "); aPrint_IntDec(reading); aPrint_Char(10); } /* while (1) */ } /* main */

Revision History:

  • 2001-07-06: Example Created.
  • 2001-10-07: Corrected a typo in the TEA program by changing the obsolete "PortCounter" to the current "aPortRflxCtr". Thanks to Al McCutcheon for finding that.
  • 2002-01-11: Updated program for compatibility with Build 5 software and TEA libraries.
  • 2009-11-02: Updated example to use GP 2.0 board. Also, updated code to use new code functionality that didn't exist when this example was created. Included reflex source code.
 
 
voice: 720-564-0373, email: sales@acroname.com, address: 4822 Sterling Dr., Boulder CO, 80301-2350, privacy
© Copyright 1994-2010 Acroname, Inc., Boulder, Colorado. All rights reserved.