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.

generating 40Khz pulses with a microcontroller

Status
Not open for further replies.
Software based ambient light detection.

the sensor is controlled by a microcontroller to generate the low duty cycle pulses, you can benefit from the High and Low pulses to be able to detect any false readings due to ambient light. This is done by recording 2 different outputs of the sensor, one of them during the ON pulse (the sensor is emitting infra red light) and the other during the OFF time. and compare the results.

Output recorded during:

Software based deduction

On Off pulse
1 0 There is definitely an Obstacle in front of the
sensor

1 1 The sensor is saturated by ambient light,
thus we can't know if there is an obstacle

0 0 There is definitely Nothing in front of the
sensor, the way is clear


0 1 This reading is un logical, there is mething
wrong with the sensor.


hardware connections:

1)LED connected to PIN RC3 of micro controller;

2)IR receiver IC TSOP48 has a digital output that can be directly modulated by a micro controller. The output of the IC is on pin 1 of the IC. The output of the receiver IC is connected to pin RC2 of micro controller.

3) microcontroller generates low duty cycle pulses at pin RA2 at 40KHz.
RA2 is connected to the CONTROL input which is linked to a transmitter

the CONTROL input is connected to the source of low duty cycle pulses which could be from a 555timer but im not using a 555timer. i want to use the PIC16f690 to do that.

description:

The transmit burst is initiated from the microcontroller. The transmit burst is essentially a function that’s called whenever the microcontroller requests for it.
The 40 kHz waveform has a period of:25us


Software Algorithm
A simple delay function will be used to toggle pin RA2 .I set the high part of the output to 5uS and the low part to 20uS.

A variable is needed to keep track of the number of delays to indicate end of transmission. The total number of delays is equal to 20 (10*2). Ten is the number of pulses sent in a burst and 2 is the number of delays per pulse. Each time a delay occurs, a variable is incremented to keep track of the number of delays. Once this variable reaches 20 the transmission is complete.
Pseudo code
Set pin RA2 high. Run first delay of 5uS.
Upon completion of delay set pin RA2 low. Run second delay for 20us.
After each delay increment a variable. Keep track of variable till it reaches 20. At this point transmission is complete.


here is my code:

Code:
#include <pic.h>
#include "pic.h"
#include "math.h"
#include <stdio.h>
#include <stdlib.h>
#include "delay.h"

bit ir1,ir2;		   // 2 different outputs of sensor during On & Off pulse
unsigned char ir;	   // stores final result




void Transmit40(void)
{	
	ANSEL=0;		         // Set inputs to digital
    TRISC=0x04;	  		 //making pin RC2 input

	int t=0;
	int cnt=0; 

	while(cnt<20)              //Tx 10 IR pulses/burst
		{	if (t==0)			    
			{
				PORTA=PORTA^0x04;	//send IR, Toggles RA2
				DelayUs(5);
				ir1=RC2;		// O/P IR bit1= O/P pin of receiver IC
				cnt++;
				t=1;
				
			}
			else if (t==1)		    	
			{	
				
				PORTA=PORTA^0x04;	//stop IR, Toggles bit 2 of portA-IR control pin connected to RA2
				DelayUs(20);
				ir2=RC2;		// O/P IR bit2= O/P pin of receiver IC
				cnt++;
				t=0;
			}


			if ((ir1 == 1)&(ir2 == 0))  //Obstacle detected
			{
				ir = 1;
			}


			else
			{
				ir = 0;	// The way is clear in front of the sensor
			}

			
			RC3=ir;     //light up led connected to RC3 if detect object; 

    }
}

void main(void)
{ 


Transmit40();

}



i am a beginner. need some assistance please for my project.


i am generating low duty cycle pulses from the microcontroller to the transmitting infrared LED.

i want my project "infra red proximity detector" to be immune to ambient light.

AIM:

when receiver detects an object then the LED must light up.

when it does not detect an object, the LED must not light up.

ambient light such as a desk lamp can falsely trigger the receiver.
when i shine light onto the receiver i want the LED to remain off.

when i programed the chip and put it into the circuit. The LED pulses but i dont want this.

could some1 please assist me.
 
Last edited:
Hi do you want to read that IR module (TSOP) from the micro controller from the reflected IR signals from the transmitting IR LED?

Actually you need to define a protocol when dealing with IR modules.Otherwise any consumer based IR frequencies (38Khz,40Khz,56Khz) will trigger the IR (TSOP) module & you will see the output toggling :)
 
here is the circuit Blueroom
 

Attachments

  • shm1.jpg
    shm1.jpg
    53.1 KB · Views: 191
Yes Gayan Soyza, thats what im doing for my project. I didnt define any protocols. Uhmm didnt know i suppost 2. How do i go about doing that ???
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top