Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

USING PIC16F877'S PWM TO GENERATE 38KHZ DATA!!!!

Status
Not open for further replies.

expert

Member level 2
Joined
Nov 28, 2007
Messages
50
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,626
send ir data using pic16f877

Currently i'm using a PIC16F877 to create a pulsing(eg : 10101010) which receive from keypad to the IR transmitter to be transmitted. i wish to use the feature from the PIC16F877 which is PWM to generate a carrier frequency 38KHZ to combine with my pulsing(10101010) to send the signal from IR transmiter to IR receiver 38KHZ. The attachment below is a simple coding to send data(10101010) without using PWM as output.SO CAN ANYONE HELP ME TO AMEND THE CODING IN ORDER TO OUPUT FROM THE PIN PWM IN PIC16F877 TO GENERATE A 38KHZ CARRIER FREQUENCY!!!!!!!!!!!!!

list p=16f877,f=inhX32, x=off
include <p16f877.inc>



__CONFIG _CP_OFF & _PWRTE_ON & _XT_OSC & _WDT_OFF

ERRORLEVEL -302 ;Suppress bank warning



TMRO EQU 1
STATUS EQU 3
PORTA EQU 5
PORTB EQU 6
TRISA EQU 85H
TRISB EQU 86H
OPTION_R EQU 81H
ZEROBIT EQU 2
COUNT EQU H'0C'
TEMP EQU H'0D'

;----------------------------------


ORG 0X00
GOTO START

;SUBROUTINE SECTION----------------

;2.5mS SECOND DELAY
DELAY1 CLRF TMR0
LOOPA MOVF TMR0,W
SUBLW .1
BTFSS STATUS,ZEROBIT
GOTO LOOPA
RETLW 0

;5mS SECOND DELAY------------------
DELAY2 CLRF TMR0
LOOPB MOVF TMR0,W
SUBLW .3
BTFSS STATUS,ZEROBIT
GOTO LOOPB
RETLW 0

;7.5mS SECOND DELAY-----------------
DELAY3 CLRF TMR0
LOOPC MOVF TMR0,W
SUBLW .6
BTFSS STATUS,ZEROBIT
GOTO LOOPC
RETLW 0

;CONFIGURATION SECTION--------------

START BSF STATUS,5
MOVLW B'00011110'
MOVWF TRISA
MOVLW B'00000000'
MOVWF TRISB
CLRF TRISC
MOVLW B'00000010'
MOVWF OPTION_R

BCF STATUS,5
CLRF PORTA
CLRF PORTB
;PROGRAM STARTS NOW-----------------

BEGIN BTFSC PORTA,0
GOTO BEGIN
MOVLW B'10101010'
MOVWF TEMP

BCF PORTB,1
CALL DELAY1
BSF PORTB,1
CALL DELAY3

TESTA0 BCF PORTB,1
CALL DELAY1
BTFSC TEMP,0
GOTO SETA0
GOTO CLRA0

SETA0 BSF PORTB,1
CALL DELAY2
GOTO TESTA1

CLRA0 BSF PORTB,1
CALL DELAY1

TESTA1 BCF PORTB,1
CALL DELAY1
BTFSC TEMP,1
GOTO SETA1
GOTO CLRA1

SETA1 BSF PORTB,1
CALL DELAY2
GOTO TESTA2

CLRA1 BSF PORTB,1
CALL DELAY1

TESTA2 BCF PORTB,1
CALL DELAY1
BTFSC TEMP,2
GOTO SETA2
GOTO CLRA2

SETA2 BSF PORTB,1
CALL DELAY2
GOTO TESTA3

CLRA2 BSF PORTB,1
CALL DELAY1

TESTA3 BCF PORTB,1
CALL DELAY1
BTFSC TEMP,3
GOTO SETA3
GOTO CLRA3

SETA3 BSF PORTB,1
CALL DELAY2
GOTO TESTA4

CLRA3 BSF PORTB,1
CALL DELAY1

TESTA4 BCF PORTB,1
CALL DELAY1
BTFSC TEMP,4
GOTO SETA4
GOTO CLRA4

SETA4 BSF PORTB,1
CALL DELAY2
GOTO TESTA5

CLRA4 BSF PORTB,1
CALL DELAY1

TESTA5 BCF PORTB,1
CALL DELAY1
BTFSC TEMP,5
GOTO SETA5
GOTO CLRA5

SETA5 BSF PORTB,1
CALL DELAY2
GOTO TESTA6

CLRA5 BSF PORTB,1
CALL DELAY1

TESTA6 BCF PORTB,1
CALL DELAY1
BTFSC TEMP,6
GOTO SETA6
GOTO CLRA6

SETA6 BSF PORTB,1
CALL DELAY2
GOTO TESTA7

CLRA6 BSF PORTB,1
CALL DELAY1

TESTA7 BCF PORTB,1
CALL DELAY1
BTFSC TEMP,7
GOTO SETA7
GOTO CLRA7

SETA7 BSF PORTB,1
CALL DELAY2
CLRF PORTB
GOTO BEGIN

CLRA7 BSF PORTB,1
CALL DELAY1
CLRF PORTB
GOTO BEGIN
END
 

pic 38 khz pwm

One suggestion.

Set up the PWM to generate 38KHz - 25% duty cycle. Switch PWM on and off as per bits at the required frequency.

Cheers

Ravi
 

38 khz pwm

yeah,, i also got such idea that send one bit n stop it and then send second bit then stop it , but problem is i not familiar using with PIC, do u mind provide me some source?????

thxs
 

pic16f877a pwm

babatundeawe said:
HOW CAN I GENERATE 50HZ USING THIS MCU
To generate 50 Hz from any I/O pin is easy, but generating from the PWM is a problem since you will have to sloooooow down the clock to the PWM engine.

50HZ bsf portx,pwm
call delay10ms
bcf portx,pwm
call delay10ms
retlw 00

But then it also depends on what other work the uC does. You can also generate this 50Hz through interrupt.

expert said:
yeah,, i also got such idea that send one bit n stop it and then send second bit then stop it , but problem is i not familiar using with PIC, do u mind provide me some source?????
I have not tried this method so I do not have a code for this, but it can be done.

Load PWM with 00h, so the PWM is shut off and then when you want 25% duty cycle, load 3Fh based on the timing :-D.

Cheers

Ravi
 

tmro a 38khz

can u write the initialization for PWM coding according to ur concept for me to refer??pls

thxs
 

pwm with pic16f877

pwminit

clrf ccp1con
clrf tmr2
movlw 0FFh
movwf pr2

clrf t2con
movlw 0FFh
movwf ccp1con
bsf t2con,tmr2on

retlw 00

You may have to change the value for 38KHz.

Cheers

Ravi
 

tmr0 a 38khz

pwminit

clrf ccp1con
clrf tmr2
movlw 0FFh
movwf pr2

clrf t2con
movlw 0FFh
movwf ccp1con
bsf t2con,tmr2on

retlw 00

can u do me a favour, combine the initialization with my data to generate 38KHZ???
i will appreciate it
plsssssss
thxxxxxx
 

38 khz pwm with pic16f877a

Check this site out. There is a software to calculate values for the various peripherals for PICmicro.

h**p://www.mister-e.org/pages/homepag.html :D

Happy PICking

Ravi
 

create 38 khz frequency using pwm

ravimarcus said:
Check this site out. There is a software to calculate values for the various peripherals for PICmicro.

h**p://www.mister-e.org/pages/homepag.html :D

Happy PICking

Ravi

thxs for the website but i still have some problem with PWM!!!
thxssss
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top