Generate PWM signal?

Discussion in 'Embedded Systems and Microcontrollers' started by winson, Feb 8, 2009.

  1. winson

    Thread Starter Member

    Dec 3, 2008
    23
    0
    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.
     
  2. FastEddie

    Active Member

    Jul 14, 2007
    35
    0
  3. winson

    Thread Starter Member

    Dec 3, 2008
    23
    0
    Thanks everybody for reply,

    For my PIC16F877A, i was running it by a 20MHz crystal. So it is related to PWM signal generation?
     
  4. winson

    Thread Starter Member

    Dec 3, 2008
    23
    0
    Hi everybody,

    I have succesfull generate the 38KHz PWM square wave and it look nice, but after i add in the PWM code to my program, the LCD which is control by the same PIC was not working correctly and it is ok without the PWM code added. The LCD was sometime fail to initialize and display one line of black square and sometime work correctly.

    So anybody know why this is happening? It look like affect by the PWM.

    thanks
     
  5. winson

    Thread Starter Member

    Dec 3, 2008
    23
    0
    Dont Know why, this few days the program was running well hopefully the unstable problem will not repeat again. But anyway thanks.
     
  6. russ_hensel

    Well-Known Member

    Jan 11, 2009
    818
    47

    I think you are off on the wrong track. The carrier should probably be a fixed frequency, fixed duty cycle ( 50% ? ) wave. PWM is to modulate the duty cycle. All you need is any old output pin that you turn on and off. Could use a timing delay, a timer/counter, or interrupt programming. C is fine, no need to use asm.
     
  7. winson

    Thread Starter Member

    Dec 3, 2008
    23
    0
    Hi,

    Yes you are correct. PWM is to modulate the width or duty cycle of the signal, but what i'm doing now is just "borrow" the square wave that generated by PWM and use the signal for frequency modulation in infrared communication.

    By the way, i also already able to use this PWM signal(455KHz) as the carrier signal for my infrared UART transmission at 19.2kBaud(19.2kbps). But the range that i can achieve is only around 5 meter and i was using Vishay 455kHz TSOP7000 as the receiver, Vishay TSAL6200 IR LED as the transmiiter. So anybody can give some hints on how to boost the range? (From the datasheet, it can achieve at least 12 meter of range)

    Actually now i'm using a n-channel MOSFET(STP36NF06L) to the drive the IR LED with 93mA of current because MOSFET can allow high current to flow through the IR LED. To make the 455KHz PWM signal ON/OFF with the UART Tx signal, i was using an CMOS NOR gate IC (Texas Instrument CD4001BE) 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 a lot...
     
    Last edited: Feb 28, 2009
  8. winson

    Thread Starter Member

    Dec 3, 2008
    23
    0
    Finally solve the problem, the IC when source too much of current then it's output voltage will drop to 2.5V.

    Thanks everybody.
     
Loading...