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.

16f877a pwm code ported to 18f452 wont work pls help

Status
Not open for further replies.

babatundeawe

Full Member level 5
Joined
Apr 12, 2007
Messages
244
Helped
16
Reputation
32
Reaction score
12
Trophy points
1,298
Location
Nigeria
Activity points
2,738
i thought i ve got hang on it until i was disapointed. i ported a pwm code from 16f877a to 18f452 and it wudnt work.

i hve tried to cahnge so many settings gone through the datasheet over and over but cant find wats wrong with the code.

someone please help.

attached is my code and circuit diagram
 

Attachments

  • hpwm.rar
    13 KB · Views: 81

What PWM duty and frequency do you want. I will write a code in mikroC. Mention your Crystal frequency.
 

oh thanks rajik but i use protonbasic. but for learning sake, just use any frequency and crystal let me see if i can port it to basic maybe i can solve my problem there.
 

oh thanks rajik but i use protonbasic. but for learning sake, just use any frequency and crystal let me see if i can port it to basic maybe i can solve my problem there.


Hi,

Some of my working 18F4520 assembly code that may help.

Also check your Config code for the correct output pin for CCP2

; CCP2 Mux bit:
; CCP2MUX = OFF CCP2 input/output is multiplexed with RB3
; CCP2MUX = ON CCP2 input/output is multiplexed with RC1

pwm_setup ; sequence from datasheet

movlw b'11111001' ; period = 2000 hz at 4hz with tm2 prescaler 4
movwf PR2

clrf CCPR1L ; set pwm1 duty to zero
clrf CCPR2L ; set pwm2 duty to zero

bcf TRISC,2 ; ensure /set ccp1/2 ports to output
bcf TRISB,3

movlw b'01111100' ; tmr2=ON,pre=1:4
movwf T2CON
bsf T2CON,TMR2ON

movlw b'00111100' ; set ccp1 to pwm mode
movwf CCP1CON

movlw B'00111100' ; set ccp2to pwm mode
movwf CCP2CON



; Both PWMs now active but with 99% off or 0.18v on 12v output rail


later

movlw 0x28 ; raise LED1 PWM
movwf CCPR1L

etc
 

Hi,

Some of my working 18F4520 assembly code that may help.

Also check your Config code for the correct output pin for CCP2

thanks i will see how i can translater it to basic
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top