+ Reply to Thread
Results 1 to 7 of 7

Thread: PIC 16F876 pwm issues.

  1. #1
    EDroscher Newbie
    Join Date
    Jan 2009
    Posts
    3

    PIC 16F876 pwm issues.

    Hi,

    Is it possible to set up a PIC 16F876 to receive IR data and increase/decrease the PWM output depending on the data received?

    Many thanks!


  2. #2
    Super Moderator Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent
    Join Date
    Nov 2003
    Location
    Derbyshire, UK
    Posts
    29,372

    Quote Originally Posted by EDroscher View Post
    Hi,

    Is it possible to set up a PIC 16F876 to receive IR data and increase/decrease the PWM output depending on the data received?

    Many thanks!
    Yes, perfectly possible, and quite easy. One of my tutorials shows how to set up two channel PWM and vary it by simple data changes - it's intended for speed control of a robot.
    PIC programmer software, and PIC Tutorials at:
    http://www.winpicprog.co.uk

  3. #3
    gramo Excellent gramo Excellent gramo Excellent gramo Excellent gramo Excellent gramo Excellent
    Join Date
    Oct 2006
    Location
    Australia
    Posts
    1,207
    Blog Entries
    3

    I was actually playing around with IR not that long ago, and customized one of the Swordfish (a PIC Basic compiler) UART libraries to modulate the signal for infrared data transmission, the results were great.

    Like most compilers, SF has its own software UART routines, but when modified to turn on/off a 38Khz PWM signal instead of making a pin high/low, the result looks like this;


    And what does that look like? Well its now modulated UART ready to control an infrared LED to transmit the data!!


    How do you go about recieving the signal? The use of a "logic output" IR reciever makes life easy. It will provide a logic high (5V) should a 38Khz signal be detected. You have now successfully demodulated the IR encoded UART data!



    It was as if two PIC's were connected by a wire and UART data was being sent from one to another, but of course they can be many many meters away (my hall way is 17 meters and I did not get any errors - it would even work around corners and into other rooms because of the high intensity IR Leds I was using)

    Transmit Program:

    Code:
    Device = 18F2550
    Clock = 8
    Config FOSC = INTOSCIO_EC
    
    Include "INTOSC8.bas"
    Include "PWM.bas"
    Include "IR_UART.bas"
    
    Dim Variable As Byte
    
    // start of main program
    PWM.SetFreq(38000)
    PWM.SetDuty1(50)
    PWM.Start1
    IR_UART.SetTX(PORTC.2)
    IR_UART.SetMode(umTrue)
    IR_UART.SetBaudrate(sbr300)
    
    Variable = 0
    
    Low(PORTC.0)
    While True
        Inc(Variable)
        IR_UART.Write(Variable)
        DelayMS(500)
    Wend
    
    Receiver Program:
    Code:
    Device = 18F2550
    Clock = 8
    Config FOSC = INTOSCIO_EC
    
    #option LCD_DATA = PORTB.4 
    #option LCD_RS = PORTB.0
    #option LCD_EN = PORTB.1
    
    Include "INTOSC8.bas"
    Include "IR_UART.bas"
    Include "convert.bas"
    Include "lcd.bas"
    
    Dim Variable As Byte
    
    IR_UART.SetRX(PORTC.2)
    IR_UART.SetMode(umTrue)
    IR_UART.SetBaudrate(sbr300)
    
    DelayMS(150)
    LCD.Cls
    LCD.WriteAt(1,1,"IR UART")
    
    While True
        IR_UART.Read(Variable)
        LCD.WriteAt(2,1,Convert.DecToStr(Variable,3))
    Wend
    
    Of course a lot more information can be found here Spencys digital-diy 18F PIC micro - Infrared IR Modulated UART

    Might help you out on the IR side of things, manipulating PWM is extremely easy as well, consider Spency's digital-diy 18F PIC micro Tutorial - PWM

  4. #4
    gramo Excellent gramo Excellent gramo Excellent gramo Excellent gramo Excellent gramo Excellent
    Join Date
    Oct 2006
    Location
    Australia
    Posts
    1,207
    Blog Entries
    3

    The only downside to all of that is I use Swordfish to create my programs, you can download a free version of it here

    (note, it only supports 18F devices.. 18F PIC's are simply an advancement in micro controller technology. They are 16F's without the drawbacks, and have more hardware peripheral features built in)

  5. #5
    Help us help you blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent
    Join Date
    Jan 2007
    Location
    Toronto, Canada
    Posts
    10,565
    Blog Entries
    5

    Great code Gramo I never noticed that Swordfish has an IR module, I can't wait to give it a try.
    Bill
    Smart Kits build Smart People

    http://www.blueroomelectronics.com/

  6. #6
    gramo Excellent gramo Excellent gramo Excellent gramo Excellent gramo Excellent gramo Excellent
    Join Date
    Oct 2006
    Location
    Australia
    Posts
    1,207
    Blog Entries
    3

    Quote Originally Posted by blueroomelectronics View Post
    Great code Gramo I never noticed that Swordfish has an IR module, I can't wait to give it a try.
    Cheers Bill

    The IR module is a user library, it can be downloaded from the bottom of this page.

    For anyone wondering what to do/how to use a user library in SF, maybe this will help?

  7. #7
    EDroscher Newbie
    Join Date
    Jan 2009
    Posts
    3

    That's a lot of great information - thank you!

    Many thanks!

+ Reply to Thread

Similar Threads

  1. pic 16f876 adc conversion
    By fathy in forum Micro Controllers
    Replies: 4
    Latest: 1st April 2008, 09:23 PM
  2. about 16F876 MICROCONTROLLER
    By bonasah in forum Chit-Chat
    Replies: 3
    Latest: 2nd November 2007, 03:19 PM
  3. Wake up PIC 16F876??
    By vijayk in forum Micro Controllers
    Replies: 3
    Latest: 9th March 2006, 06:26 AM
  4. 16F876 vs 16F877
    By heida11 in forum Micro Controllers
    Replies: 6
    Latest: 4th February 2004, 09:04 AM
  5. 16f876 pic
    By stanley in forum Micro Controllers
    Replies: 2
    Latest: 19th December 2003, 12:47 PM

Tags for this Thread