At 10:55 11/06/1997 -0400, you wrote: >Hello, > >Does anyone could supply me some code in C (preference), to implement a PWM >or where i can find information about this. As you ask for PWM code, here a sample code extracted from UMPS http://idls.izarbel.tm.fr/entp/techer/P01.HTM or http://sistudio.com/umps This code produce a continous rectangular signal and it is easy to change cycle modulation, just writting HiPWM and LoPWM cycles when you need. I think "C" code will be a little slow, but it depend of what you are searching for PWM at 10HZ or at 1KHZ Regards, Philippe. ;--------------------------------------------------------------------------- ------- ; PWM Output sample INTW equ $0C INTStatus equ $0D HiPWM equ $0E LoPWM equ $0F PWMPORT equ PORTA Cntl equ 0 PWMCfg equ %11110 ;--------------------------------------------------------------------------- ------- ; **** RESET vector org 0 goto StartUp ;--------------------------------------------------------------------------- ------- ; **** INTERRUPT vector org 4 Intr: movwf INTW ; Save W and Status registers swapf STATUS,W movwf INTStatus bcf INTCON,T0IF ; Clear TIMER 0 Int flag btfsc PWMPORT,cntl ; If cntl is Set, then Reset cntl bit goto Intr_1 bsf PWMPORT,cntl ; be carrefull here as BSF is Read-Modify-Write movf HiPWM,W ; instruction and it can change other pin state movwf TMR0 goto IntrEnd Intr_1: bcf PWMPORT,cntl movf LoPWM,W ; Load LOW cycle in TIMER0 movwf TMR0 IntrEnd: swapf INTStatus,W ; Restore W and Status registers movwf STATUS swapf INTW swapf INTW,W retfie ;--------------------------------------------------------------------------- ------- StartUp: bcf INTCON,GIE ; ***** Disable INT bsf STATUS,RP0 ; Set PAGE 1 access movlw PWMCfg movwf TRISA movlw %00000001 ; Timer Base = 4µS movwf OPTION bcf STATUS,RP0 ; Set PAGE 0 access clrf PORTA clrf TMR0 ; Timer 0 = 00 movlw %10100000 ; Enable TMR0 Interrupt movwf INTCON ;--------------------------------------------------------------------------- ------- movlw $A0 ; Set High pulse time to: 0x100 - 0xA0 movwf HiPWM movlw $C0 ; Set Low pulse time to: 0x100 - 0xC0 movwf LoPWM movwf TMR0 Loop: goto Loop ; Loop forever ----------- END OF MESSAGE ----------------------------------