Author Topic: Generate 38kHZ PWM signal?  (Read 6420 times)

0 Members and 1 Guest are viewing this topic.

Offline winsonTopic starter

  • Jr. Member
  • **
  • Posts: 16
  • Helpful? 0
Generate 38kHZ PWM signal?
« on: February 08, 2009, 01:20:59 PM »
Hi everybody,

Anybody can point me to a right direction with some sample code regarding how to generate a PWM signal? Actually i was trying to generate a 38kHz PWM signal as the carrier for my UART IR transmission, then when i need to transmit data i will make the 38KHz PWM signal ON/OFF to drive an infrared LED and communicate with the IR receiver.

I was using CCS C compiler(just start learn up assembly) and PIC16F877A, and i haved read through the PWM section of the data sheet but just not so understand about how to set the register.

Anybody can help?

Thanks.

paulstreats

  • Guest
Re: Generate 38kHZ PWM signal?
« Reply #1 on: February 08, 2009, 01:59:05 PM »
It would be easier to use an IR encoder ic like this: MCP2120


Offline Soeren

  • Supreme Robot
  • *****
  • Posts: 4,672
  • Helpful? 227
  • Mind Reading: 0.0
Re: Generate 38kHZ PWM signal?
« Reply #2 on: February 08, 2009, 02:07:39 PM »
Hi,

No need to use PWM. Just set up a timer/counter divider according to your X-tal frequency and let it rip when needed.
Regards,
Søren

A rather fast and fairly heavy robot with quite large wheels needs what? A lot of power?
Please remember...
Engineering is based on numbers - not adjectives

Offline winsonTopic starter

  • Jr. Member
  • **
  • Posts: 16
  • Helpful? 0
Re: Generate 38kHZ PWM signal?
« Reply #3 on: February 09, 2009, 10:57:01 AM »
Thanks everybody for reply,

Yes, the IR encoder IC really a good solution to infrared application, but i'm just wondering whether can it be done by just the software so just give a try on it.

Since i was the beginner in the timer and PWM stuff, so regarding using timer/counter divider to make IR communication, can i get some hint like code snippet?

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,703
  • Helpful? 173
    • Society of Robots
Re: Generate 38kHZ PWM signal?
« Reply #4 on: February 15, 2009, 05:30:37 AM »
Using IrDA (from an IR encoder IC) will give you better range.

What range do you require?

I haven't tried myself, but not using it I've heard you can only get a few feet range. With IrDA you can the range of a TV remote.

Offline Soeren

  • Supreme Robot
  • *****
  • Posts: 4,672
  • Helpful? 227
  • Mind Reading: 0.0
Re: Generate 38kHZ PWM signal?
« Reply #5 on: February 15, 2009, 04:20:28 PM »
Hi,

I haven't tried myself, but not using it I've heard you can only get a few feet range. With IrDA you can the range of a TV remote.

Using an integrated receiver, 10 m is easily obtainable (range depends on type of receiver, alignment and IR power).
After all, remotes use the same scheme and I have gone ~18m once I experimented with IR remote data transfers.

With optics, up to around 1.5 km/~1 mile is possible :)
Regards,
Søren

A rather fast and fairly heavy robot with quite large wheels needs what? A lot of power?
Please remember...
Engineering is based on numbers - not adjectives

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,703
  • Helpful? 173
    • Society of Robots
Re: Generate 38kHZ PWM signal?
« Reply #6 on: February 17, 2009, 12:12:43 PM »
Using an integrated receiver, 10 m is easily obtainable (range depends on type of receiver, alignment and IR power).
After all, remotes use the same scheme and I have gone ~18m once I experimented with IR remote data transfers.

With optics, up to around 1.5 km/~1 mile is possible :)
Well I meant with just a basic setup gave poor range . . . like the IR LED connected to directly to Tx . . . actually I'm quoting dunk that it has poor range.

But lots of things you can do to boost signal, modulated or not . . .

Aim it perfectly. If you don't have control of aim, then you'd need lots of LED's in different directions. Using a MOSFET to amplify voltage would boost range too.

Offline ArcMan

  • Supreme Robot
  • *****
  • Posts: 519
  • Helpful? 4
  • Mmmm... Plasma
Re: Generate 38kHZ PWM signal?
« Reply #7 on: February 17, 2009, 01:38:43 PM »
I agree with Soeren, but here's some PWM code for the CCS C compiler if you need it.

Setup:

Code: [Select]
/************************
* PWM Setup
************************/
setup_ccp1(CCP_PWM);
setup_ccp2(CCP_PWM);

// Setup Timer 2 for a 4.9 kHz PWM frequency
// PWM Period = (1/clock)*4*t2div*(period+1) = (1/20000000)*4*4*(254+1) = 0.204 ms (which is 4.9 kHz)
setup_timer_2(T2_DIV_BY_4, 0xFE, 1);

Usage:

Code: [Select]
// Set the motor PWM duty cycles
// 0 = 0%, 255 = 100%
if (left_pwm_pct >= 95)
left_pwm_pct = 100;
left_pwm_duty = (int)left_pwm_pct * 2.55;
set_pwm1_duty(left_pwm_duty);

if (right_pwm_pct >= 95)
right_pwm_pct = 100;
right_pwm_duty = (int)right_pwm_pct * 2.55;
set_pwm2_duty(right_pwm_duty);

Offline Mif

  • Beginner
  • *
  • Posts: 2
  • Helpful? 0
  • www.TupperBot.com
    • TupperBot.com
Re: Generate 38kHZ PWM signal?
« Reply #8 on: February 25, 2009, 03:57:41 PM »
Hi!
I'm new in this forum, so i hope my answer will help :)

ArcMan's code will work fine, and is what i use to control the speed of my robot, but it seems like you just need to generate one signal, right?

If so, here is a simple code generated directly from the PicWizard:

Code: [Select]
Inserted into .c file in main():

   setup_ccp1(CCP_PWM);
   set_pwm1_duty(264);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);

Offline winsonTopic starter

  • Jr. Member
  • **
  • Posts: 16
  • Helpful? 0
Re: Generate 38kHZ PWM signal?
« Reply #9 on: February 26, 2009, 03:44:56 AM »
Hi everybody,

I have already succesful generate the PWM signal, thanks for the help from you guys. Beside, i also already able to use this PWM signal as the carrier signal for my infrared UART transmission at 19.2kBaud. The range that i can achieve is around 7m - 8m and i was using Vishay 455kHz TSOP7000 as the receiver, Vishay TSAL6200 IR LED as the transmiiter. Can anybody explain in detail how to use a MOSFET to boost the range?

Actually now i'm using a n-channel MOSFET to the drive the IR LED but the voltage(Vf) of the LED look like did not amplify. To make the 455KHz PWM signal ON/OFF with the UART Tx signal, i was using an CMOS NOR gate IC to "NOR" them together and this make the IR LED "blinking" when the UART data is "LOW" or "0", but one funny thing happen, when the 5V UART Tx signal "NOR" together with the 5V 455KHz PWM signal, from an oscilloscope, the output from the NOR gate IC is a 2.5V modulated PWM signal and the output of the IC is connected to the gate of the MOSFET to drive IR LED, anybody know why it was happenning?

But then after i disconnect the IC's output from the gate of the MOSFET then the IC's output will give a 5V PWM modulated signal.

Any suggestion will be appreciate
Thanks.. :D




Offline ArcMan

  • Supreme Robot
  • *****
  • Posts: 519
  • Helpful? 4
  • Mmmm... Plasma
Re: Generate 38kHZ PWM signal?
« Reply #10 on: February 26, 2009, 12:31:58 PM »
I think I know why you are seeing a reduced voltage at the output of your CMOS NOR gate.  That CMOS gate does not have enough current sourcing capability to drive your MOSFET gate properly.  You need something that has the ability to drive that MOSFET gate at frequency.  The MOSFET gate has capacitance, which is why it is loading your NOR gate.  Plus, you need to drive that MOSFET at 8V, not 5V, to switch it completely ON.  Use an NPN transistor between your NOR gate and the MOSFET to boost voltage and current.

Offline Soeren

  • Supreme Robot
  • *****
  • Posts: 4,672
  • Helpful? 227
  • Mind Reading: 0.0
Re: Generate 38kHZ PWM signal?
« Reply #11 on: February 26, 2009, 01:52:19 PM »
Hi,

i also already able to use this PWM signal as the carrier signal for my infrared UART transmission at 19.2kBaud. The range that i can achieve is around 7m - 8m and i was using Vishay 455kHz TSOP7000 as the receiver, Vishay TSAL6200 IR LED as the transmiiter. Can anybody explain in detail how to use a MOSFET to boost the range?
[...]
Any suggestion will be appreciate

I suggest that you either use a 38kHz IR-receiver, or up the carrier to 455 kHz, since what you do is sort of a dead case - a range of 7..8m is actually quite good with such a huge frequency mismatch.


Btw. Where did you get the TSOP700 and at what price? I'd like to find a place cheaper than the $7 that a Danish seller wants (which is utterly out of proportion compared to what I pay for 38kHz receivers).
Regards,
Søren

A rather fast and fairly heavy robot with quite large wheels needs what? A lot of power?
Please remember...
Engineering is based on numbers - not adjectives

Offline winsonTopic starter

  • Jr. Member
  • **
  • Posts: 16
  • Helpful? 0
Re: Generate 38kHZ PWM signal?
« Reply #12 on: February 27, 2009, 03:54:50 AM »
I think I know why you are seeing a reduced voltage at the output of your CMOS NOR gate.  That CMOS gate does not have enough current sourcing capability to drive your MOSFET gate properly.  You need something that has the ability to drive that MOSFET gate at frequency.  The MOSFET gate has capacitance, which is why it is loading your NOR gate.  Plus, you need to drive that MOSFET at 8V, not 5V, to switch it completely ON.  Use an NPN transistor between your NOR gate and the MOSFET to boost voltage and current.


Hi ArcMan,

I think what you say is really true. I was using the Texas Instrument CD4001BE NOR gate and after i read thru in detail the datasheet of the IC i found out the IC will output 4.6V when it source 0.5 - 1mA of current and it will output 2.5V when it need to source 1.6 - 3.2mA of current. Currently i was using the STP36NF06L MOSFET and the data sheet does not tell it need 8V to fully turn ON the MOSFET, so thanks for your information.

Now i was half way looking on the datasheet for the ULN2003A darlington array IC, it look like able perform the same function that similar to the combination of the NPN transistor and MOSFET to drive IR LED, so this IC possible to drive an IR LED? Anybody can give me some comment? Since using NPN BJT and MOSFET to drive IR LED is more complicated.

Btw, i know that an IR LED is a current dependence device. So after we increase the value of forward voltage it really help to boost its range? From datasheet the Vf of IR LED is 1.3V and now there is already 1.1V drop to my IR LED already so if i further increase it's Vf will i destroy the LED?

Thanks.
 


« Last Edit: February 27, 2009, 03:56:53 AM by winson »

Offline winsonTopic starter

  • Jr. Member
  • **
  • Posts: 16
  • Helpful? 0
Re: Generate 38kHZ PWM signal?
« Reply #13 on: February 27, 2009, 04:00:10 AM »


I suggest that you either use a 38kHz IR-receiver, or up the carrier to 455 kHz, since what you do is sort of a dead case - a range of 7..8m is actually quite good with such a huge frequency mismatch.


Btw. Where did you get the TSOP700 and at what price? I'd like to find a place cheaper than the $7 that a Danish seller wants (which is utterly out of proportion compared to what I pay for 38kHz receivers).


Hi Soeren,

Yup, now i using the TSOP7000 receiver with 455KHz PWN carrier signal, and just can get a range of 7m.

The IR reciever i buy it from the internet, www.farnell.com. It is around $5



Offline ArcMan

  • Supreme Robot
  • *****
  • Posts: 519
  • Helpful? 4
  • Mmmm... Plasma
Re: Generate 38kHZ PWM signal?
« Reply #14 on: February 27, 2009, 12:43:30 PM »
Now i was half way looking on the datasheet for the ULN2003A darlington array IC, it look like able perform the same function that similar to the combination of the NPN transistor and MOSFET to drive IR LED, so this IC possible to drive an IR LED? Anybody can give me some comment? Since using NPN BJT and MOSFET to drive IR LED is more complicated.

The ULN2003A will do a fine job driving an LED.

Offline Soeren

  • Supreme Robot
  • *****
  • Posts: 4,672
  • Helpful? 227
  • Mind Reading: 0.0
Re: Generate 38kHZ PWM signal?
« Reply #15 on: February 27, 2009, 08:38:54 PM »
Hi,

Yup, now i using the TSOP7000 receiver with 455KHz PWN carrier signal, and just can get a range of 7m.

The IR reciever i buy it from the internet, www.farnell.com. It is around $5
Thanks, still too darn expensive when you have hundreds of the 38kHz variety though.

You are better off using a BjT. A small circuit with current limiting and a short part of the pulse with an extra shot of power is here:
http://That.Homepage.dk/PDF/IR_LED_Driver.pdf
This should get you a fair distance with regular IR LEDs, just remember to make the signal within specs:

"The burstlength should be between 22μs and 500μs.
Separation time between two consecutive bursts should be at least 26 μs.
If the data bursts are longer than 500 μs then the envelope duty cycle is limited to 25 %"
« Last Edit: February 27, 2009, 08:58:26 PM by Soeren »
Regards,
Søren

A rather fast and fairly heavy robot with quite large wheels needs what? A lot of power?
Please remember...
Engineering is based on numbers - not adjectives

 


Get Your Ad Here