PDA

View Full Version : ECCP module problem



hell_pk
- 29th August 2007, 08:36
why is this code not working on 18F1320.any ideas!!!!

Define OSC 8
ADCON1 = 7

DUTY var WORD

P1A var PORTB.3 ' ECCP pin defines . Replace those with your actual device pins
P1B var PORTB.2
P1C var PORTB.6
P1D var PORTB.7
TMR2IF var PIR1.1 ' TMR2 interrupt flag



P1A=1 'Tristate
P1B=1 ' Tristate
P1C=1 ' Tristate
P1D=1 'Tristate
PR2 = 249 ' set PR2 to 249 , that is 1Khz PWM frequency
CCP1CON =0 ' PWM generator stopped
CCPR1L = 0 ' zero Duty Cycle
'CLEAR TMR2IF
TMR2IF=0



FORWARD:
DUTY=200
CCP1CON=0 ; stop the PWM generator
P1A=0 ' P1A = 1 ; P1A = active
P1B=1 ; P1B = tristate
P1C=1 ; P1C = tristate
P1D=0 ; P1D = PWM modulated
;------------------------
CCP1CON.4 = DUTY.0 ; here we stat loading the CCPR1
CCP1CON.5 = DUTY.1 ; with the value of DUTY Cycle parameter
CCPR1L = DUTY >> 2 ;
;-----------------------
CCP1CON = %01001100 ; set CCP1CON to full bridge , high output, Forward
T2CON = %00000101 ; start TMR2 , also TMR2 prescaler 1:4
WHILE TMR2IF = 0
WEND ; wait for a TMR2 period to expire
RETURN

Darrel Taylor
- 29th August 2007, 14:15
why is this code not working on 18F1320.any ideas!!!!



P1A var PORTB.3 ' ECCP pin defines .
P1B var PORTB.2
P1C var PORTB.6
P1D var PORTB.7
TMR2IF var PIR1.1 ' TMR2 interrupt flag



P1A=1 'Tristate
P1B=1 ' Tristate
P1C=1 ' Tristate
P1D=1 'Tristate

Those are changing the PORT value, not it's input/output state.

Try TRISB.x for P1A-D.
<br>

hell_pk
- 31st August 2007, 05:28
Hi!
still not working!!!

Darrel Taylor
- 31st August 2007, 09:07
Is there more to your program?

If not, then the FORWARD routine is RETURNing but it wasn't called with a GOSUB.

Also,

;------------------------
CCP1CON.4 = DUTY.0 ; here we stat loading the CCPR1
CCP1CON.5 = DUTY.1 ; with the value of DUTY Cycle parameter
CCPR1L = DUTY >> 2 ;
;-----------------------
CCP1CON = %01001100 ; set CCP1CON to full bridge , high output, Forward

By setting CCP1CON after seting to 2 LSB's of the dutycycle, it overwrites those bits and you lose resolution.
<br>

hell_pk
- 3rd September 2007, 09:33
thanks its done with a little bit of messing around.i wasnt using my head and was relying too much on forum help.
btw thanks to fanie & gabi as well. :)