Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
Tools
Old 25th January 2009, 09:17 AM   #1
Default 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!
EDroscher is offline  
Old 25th January 2009, 09:31 AM   #2
Default

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
Nigel Goodwin is online now  
Old 25th January 2009, 10:20 AM   #3
Default

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
__________________
digital-diy.com - Hobby microcontroller projects and tutorials. Assembly, PICBasic and C examples.

gramo is offline  
Old 25th January 2009, 10:23 AM   #4
Default

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.

gramo is offline  
Old 25th January 2009, 04:15 PM   #5
Default

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/
blueroomelectronics is offline  
Old 25th January 2009, 11:31 PM   #6
Default

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?
__________________
digital-diy.com - Hobby microcontroller projects and tutorials. Assembly, PICBasic and C examples.

gramo is offline  
Old 26th January 2009, 12:29 AM   #7
Default

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

Many thanks!
EDroscher is offline  
Reply

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



All times are GMT. The time now is 09:07 PM.


Electronic Circuits  |  Learning Electronics
eXTReMe Tracker