I have a problem on the continuity of my PWM module. The PWM runs at 1kHz, 5% duty cycle The PWM module works fine for 9.48ms (10 cycles) and then it stop for=20 31.43ms and then it start again I can't find the reason why it stop for this 31.43ms..... eg. _1111111111__________________1111111111__________ Regards Francois Here is my code. list p=3D16f88 ; list directive to define processor #include ; processor specific variable definitions errorlevel -302 ; suppress message 302 from list file ;=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D ; Configuration Bits ;=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D ;Program Configuration Register 1 __CONFIG _CONFIG1, _CP_OFF & _CCP1_RB0 & _DEBUG_OFF & _WRT_PROTECT_OFF= =20 & _CPD_OFF & _LVP_OFF & _BODEN_OFF & _MCLR_ON & _PWRTE_OFF & _WDT_OFF &=20 _XT_OSC ;Program Configuration Register 2 __CONFIG _CONFIG2, _IESO_OFF & _FCMEN_OFF ;**************************************************************************= ** ; PORT Assingments ;**************************************************************************= ** ; PORT A ;**************************************************************************= ** ; #Define xxx PORTA,0 ;pin17 ; #Define xxx PORTA,1 ;pin18 ; #Define RxData PORTA,2 ;pin1 ; #Define Trigger PORTA,3 ;pin2 ; #Define xxx PORTA,4 ;pin3 ;**************************************************************************= ** ; PORT B ;**************************************************************************= ** #Define Light PORTB,0 ;pin6 PWM Output - must be digital outpu= t #Define LED PORTB,1 ;pin7 ; #Define xxx PORTB,2 ;pin8 ; #Define xxx PORTB,3 ;pin9 #Define KeyUp PORTB,4 ;pin10 #Define KeyDown PORTB,5 ;pin11 ; #Define xxx PORTB,6 ;pin12 ; #Define xxx PORTB,7 ;pin13 ;**************************************************************************= ** ; GENERAL PURPOSE REGISTERS ;**************************************************************************= ** CounterA equ 0x23 CounterB equ 0x24 CounterC equ 0x25 ADDR equ 0x2B VALUE equ 0x2C Time3KReg equ 0x36 Time3M1Reg equ 0x37 Time3M2Reg equ 0x38 w_temp EQU 0x71 ; variable used for context saving status_temp EQU 0x72 ; variable used for context saving pclath_temp EQU 0x73 ; variable used for context saving timer equ 0x74 timer1 equ 0x75 ;**************************************************************************= ** ; START ;**************************************************************************= ** ORG 0x000 ; processor reset vector goto setup ; go to beginning of setup program ORG 0x004 ; interrupt vector location movwf w_temp ; save off current W register contents movf STATUS,w ; move STATUS register into W register movwf status_temp ; save off contents of STATUS register movf PCLATH,W ; move PCLATH register into W register movwf pclath_temp ; save off contents of PCLATH register ; isr code can go here or be located as a call subroutine elsewhere call Inthandler movf pclath_temp,w ; retrieve copy of PCLATH register movwf PCLATH ; restore pre-isr PCLATH register contents movf status_temp,w ; retrieve copy of STATUS register movwf STATUS ; restore pre-isr STATUS register contents swapf w_temp,f swapf w_temp,w ; restore pre-isr W register contents retfie ; return from interrupt ;**************************************************************************= ** ; SETUP ;**************************************************************************= ** setup clrwdt bcf INTCON, GIE BANKSEL CMCON movlw 0x07 movwf CMCON ; CMCON=3D7 set comperators off ; CMCOM=3D5 set single comparator RA1=3DVin-, RA2=3DVin+(ref) BANKSEL OPTION_REG bsf OPTION_REG, 0x07 ; Disable Pull Up on PORTB - RBPU (OPTION_REG<7>). BANKSEL PORTA ; select bank of PORTA MOVLW B'00000000' MOVWF PORTA ; Initialize PORTA by ; clearing output ; data latches BANKSEL ANSEL ; Select Bank of ANSEL MOVLW 0x00 ; Configure all pins MOVWF ANSEL ; as digital inputs MOVLW b'11111111' ; Value used to ; initialize data ; direction BANKSEL TRISA MOVWF TRISA ; Set RA<7:0> as inputs BANKSEL PORTB ; select bank of PORTB movlw B'00000000' ; (RB0:RB1) =3D 0 - OTHERS =3D 1 movwf PORTB ; Initialize PORTA by ; clearing output BANKSEL TRISB ; data latches MOVLW B'11111100' ; Value used to ; initialize data ; direction MOVWF TRISB ; Set RB<7:0> as inputs ; * PWM registers configuration ; * Fosc =3D 4000000 Hz ; * Fpwm =3D 1000.00 Hz (Requested : 250 Hz) ; * Duty Cycle =3D 5 % ; * Resolution is 10 bits ; * Prescaler is 4 ; * Ensure that your PWM pin is configured as digital output ; * see more details on http://www.micro-examples.com/ ; * this source code is provided 'as is', ; * use it at your own risks ;PR2 =3D 0b11111001 BANKSEL PR2 movlw b'11111001' movwf PR2 ;T2CON =3D 0b00000111 BANKSEL T2CON movlw b'00000101' movwf T2CON ;CCPR1L =3D 0b01111100 BANKSEL CCPR1L movlw b'00001100' movwf CCPR1L ;CCP1CON =3D 0b00111100 BANKSEL CCP1CON movlw b'00011100' movwf CCP1CON ;**************************************************************************= ** ; START OF MAIN PROGRAM ;**************************************************************************= ** main CLRF STATUS ; Do initialization, Select bank 0 CLRF PCLATH ; Keep in lower 2KByte CALL Delay_1s ; allow for settle time main1 clrwdt decf timer,f btfsc STATUS,Z call togled goto main1 togled decfsz timer1,f return movlw B'00000010' xorwf PORTB,f return ;PIC Time Delay =3D 1.0000020 s with Osc =3D 4.000000 MHz Delay_1s movlw D'6' movwf CounterC movlw D'24' movwf CounterB movlw D'168' movwf CounterA loop_1s decfsz CounterA,1 goto loop_1s decfsz CounterB,1 goto loop_1s decfsz CounterC,1 goto loop_1s return ;******************************************************* Inthandler ; movf D8, w ; movwf MasterHighByte ; movwf VALUE ; movlw 0x00 ; movwf ADDR ; call PicEeWrite ; movf D9, w ; movwf MasterLowByte ; movwf VALUE ; movlw 0x01 ; movwf ADDR ; call PicEeWrite return END ; directive 'end of program' --=20 http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .