PWM for IR Proximity Sensor

Thread Starter

varuntejavarma

Joined Apr 16, 2014
36
Hello,
I have to build an Ir proximity sensor to detect any obstacle passing by. I have used TSOP 4856 sensor to detect the reflected ir signals. I have to generate Ir signals with carrier frequency at 56khz and also the 56 khz signals shouldn't be continous. ON OFF pulses of 56 khz signals should be generated. I have used two 555 timers for this purpose. one for generating 56 khz signal and other for the on off signals. THe ON pulse should be smaller than the OFF pulse(i.e., about 20- 30 % duty cycle) nad the ON pulse should contain min of 11 cycles of 56 khz signals. I have attached the picture of signal i got with the timers. But with timers, i could not achieve a desired range and have lot of problems with connections. So, i thouight of using a pic mcu for generating the pulses.

I have tried the PWM module of PIC18f4550 to generate 56 khz pulses and acheived a range of only 5 cms. Mybe its because i wasn't sending ON OFF pulses. But i do not know how to Make the 56 khz signal ON OFF at a particular freq. I am using XC8 compiler and ICD3 programmer. MY simple program for pwm is:

#include <xc.h>
#include <stdio.h>
#include <stdlib.h>
#pragma config FOSC = INTOSCIO_EC
#pragma config FCMEN = OFF
#pragma config BORV = 3
#pragma config WDT = OFF
#pragma config CPB = OFF
#pragma config CPD = OFF
void SetupClock()
{
OSCCONbits.IRCF0 = 1;
OSCCONbits.IRCF1 = 1;
OSCCONbits.IRCF2 = 1;
}
void main(void)
{SetupClock();
TRISCbits.RC2=0;
PORTCbits.RC2=0;
PR2= 0b00100011;
T2CON = 0b00000100;
CCPR1L = 0b00010001;
CCP1CON = 0b00111100;
while(1);
}


I have just started working with microcontrollers and this is my first project with mcu. I am trying the method of learning by doing. So, It would be very helpfull if someone could tell me how to do this with some explanation for a beginner (me).
 

Attachments

ErnieM

Joined Apr 24, 2011
8,377
11 cycles of 56 KHz is just under 200uS slow slow for a micro.

If you are doing nothing else with the micro a simple blocking delay is all you'd need. Expand your while loop to add:

Rich (BB code):
while(1)
{
 delay_us(200);
 // set PWM to 0% (disables pulses)
 delay_us(200);
 // set PWM to 50% (re-enables pulses)
}
If you have other things to do a timer interrupt would be a better choice. Arrange one timer to time out about every 200 uS and fire off an interrupt. Inside the interrupt handler do the same thing: flip flop the duty cycle from 50 to zero.

The first way is lots easier, almost fool proof. Try that first in case you have other issues.

Are you sure the pin is changing at all? Have the PWM fully enabled? Selected on the pin? Other functions sharted on that pin such as analog turned off?

"Sanity checks" are always a good thing when starting a micro project. See if you can toggle that pin very slowly so you can see the wiggle: easy if you have an oscilloscope, harder if you need a slow pulse for a DVM or even a visible LED.
 
Top