Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

PIC 16F876 pwm issues.

Status
Not open for further replies.

EDroscher

New Member
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!
 
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.
 
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;
**broken link removed**

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

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!
**broken link removed**


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 **broken link removed**

Might help you out on the IR side of things, manipulating PWM is extremely easy as well, consider **broken link removed**
 
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 **broken link removed**.

For anyone wondering what to do/how to use a user library in SF, maybe **broken link removed**will help?
 
Status
Not open for further replies.

Latest threads

Back
Top