![]() | ![]() | ![]() |
| |||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
![]() |
| | Tools |
| | #1 |
|
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 |
| 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.
| |
| |
| | #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
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
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
__________________ digital-diy.com - Hobby microcontroller projects and tutorials. Assembly, PICBasic and C examples. | |
| |
| | #4 |
|
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)
__________________ digital-diy.com - Hobby microcontroller projects and tutorials. Assembly, PICBasic and C examples. | |
| |
| | #5 |
|
Great code Gramo I never noticed that Swordfish has an IR module, I can't wait to give it a try.
| |
| |
| | #6 | |
| Quote:
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?
__________________ digital-diy.com - Hobby microcontroller projects and tutorials. Assembly, PICBasic and C examples. | ||
| |
| | #7 |
|
That's a lot of great information - thank you! Many thanks! | |
| |
|
| Tags |
| issues, pic, pwm |
| Thread Tools | |
| Display Modes | |
| |
Similar | ||||
| Title | Starter | Forum | Replies | Latest |
| pic 16f876 adc conversion | fathy | Micro Controllers | 4 | 1st April 2008 09:23 PM |
| about 16F876 MICROCONTROLLER | bonasah | Chit-Chat | 3 | 2nd November 2007 03:19 PM |
| Wake up PIC 16F876?? | vijayk | Micro Controllers | 3 | 9th March 2006 06:26 AM |
| 16F876 vs 16F877 | heida11 | Micro Controllers | 6 | 4th February 2004 09:04 AM |
| 16f876 pic | stanley | Micro Controllers | 2 | 19th December 2003 12:47 PM |