PDA

View Full Version : Software PWM using Timer1



muqasim
- 18th December 2009, 11:02
I have generated Software PWM of 20Khz by the help of Timer1 and it is working fine but the problem which i am facing now is that ,the main body is executing just one time only. I have attached the source code as well so please read my source code and please tell me what the hell is happening in code that main body has been executed just one time.

device=16f876a
xtal=20
DECLARE CCP1_PIN PORTc.2
PIE1 = $01 'Enable TMR1 overflow interrupt
INTCON=%11010000 'Enable Global Interrupt,Peripheral and External Interrupts
all_digital=true
ON_INTERRUPT GOTO SENSOR_INT
dim TIMER1 as tmr1l.word
DIM A AS WORD
dim B as word
Symbol T1CKPS0 = T1CON.4 ' Timer1 Input Clock Prescale Select bits
Symbol T1CKPS1 = T1CON.5 ' Timer1 Input Clock Prescale Select bits
syMbol TMR1ON = T1CON.0 ' START OR STOP TIMER1
SYMBOL FTMR1 = PIr1.0 ' TIMER1 OVERFLOW FLAG

T1CKPS0=0 'PRE SCALAR SET TO 8
T1CKPS1=0 '
TIMER1=65335'485 'TIMER OFFSET FOR TIME DELAY=100ms
low portc.4
low porta.3
TMR1ON=0'1
ftmr1=0
B=1
Pie1.1=0 'when this value=0 then main body execute and if it is=1 then main execute ONLY ONE TIME
hpwm 1,200,20000
GOTO MAIN

'************************************************* *******
main:
toggle porta.3
HIGH 7

INC B
for a=1 to 65535
NOP
nop
nop
nop
nop
next

for a=1 to 65535
NOP
nop
nop
nop
nop
next

goto main

'**********************START ISR( INTERRUPT SERVICE ROUTINE )*****************
SENSOR_INT:
if pir1.1=1 then
TIMER1=65335'485
HIGH PORTC.4
TMR1ON=1
PIR1.1=0
ENDIF

IF FTMR1=1 THEN
LOW PORTC.4
FTMR1=0
ENDIF
retfie fast
'tmr1on=0
'timer1=65410
'toggle portc.4
'ftmr1=0
'tmr1on=1
'CONTEXT RESTORE
'************************END ISR( INTERRUPT SERVICE ROUTINE)*****************

Also if i have change the value of PIE1.1=1 to PIE1.1=0 then software pwm stops and main body executes normally.

I hope someone can help me.

Acetronics2
- 18th December 2009, 11:49
Hi,

Are you sure to have posted on the right forum ???

It's MELABS PicBasicPro Forum here ...

Alain