[code] ; --- Constant values FXTAL equ D'8000000' ; bit 76543210 RA_TRIS equ b'00000000' ;*RA<1:0> used for programming and RA3 = MCLR RA_INI equ b'00000000' ; set all outputs zero RB_TRIS equ b'10110000' ;*RB7, RB5 and RB4 input, RB6 is ACK output RB_INI equ b'00000000' ; set all outputs zero RC_TRIS equ b'00000000' ;*set all outputs zero RC_INI equ b'00000000' ;*used for PWM-ECCP signal on 16F685 OPTION_INI equ b'10001000' ; Option register: no pull-up, no prescaler, wdt 1:1 INTCON_INI equ b'10001000' ; GIE, RBIE enable, PEIE disable PIE1_INI equ b'00000000' ; no interrupts on startup IOCA_INI equ b'00000000' ;*disable all interrupts on PORTA IOCB_INI equ b'10000000' ;*enable only RB7 interrupts CCP1CON_INI equ b'01111100' ;*set to ECCP, PWM and Fullbridge forward #define OUT1A 0 ; #define OUT1B 1 ; INIT: ; Do all the Bank 0 register settings ; clrf PORTA ; Make sure nothing get started clrf PORTB ; Nothing get's in clrf PORTC ; and nothing get's out clrf PIR1 movlw 0x31 ; Timer 1 on, 1:8 movwf T1CON ; Do all the Bank 1 register settings ; Banksel TRISA ; Bank 1 movlw RA_TRIS ; Set port A I/O configuration movwf TRISA movlw RB_TRIS ; Set port B I/O configuration movwf TRISB movlw RC_TRIS ; Set port C I/O configuration movwf TRISC movlw PIE1_INI movwf PIE1 movlw OPTION_INI ; Set Optionregister to no PullUps, ; no prescaller and WDT 1:1 movwf OPTION_REG clrf WPUA ; Dont use WeakPullUp on PORTA clrf IOCA ; We dont use IOC on PORTA so leave it ; Do all the Bank 2 register settings ; BANKSEL ANSEL ; Bank 2 clrf ANSEL ; Make all pin's Digital clrf ANSELH clrf WPUB ; Dont use WeakPullUps on PORTB clrf VRCON ; voltage reference off BANKSEL 0x00 [/code] > -----Oorspronkelijk bericht----- > Van: piclist-bounces@mit.edu [mailto:piclist-bounces@mit.edu] > Namens Jan-Erik Soderholm > Verzonden: woensdag 5 augustus 2009 14:20 > Aan: Microcontroller discussion list - Public. > Onderwerp: Re: [PIC] PWM wont set output bits, why? > > Where and how are your symbols defined ? > Where and how are the analog pins setup ? > > > Harry H. Arends wrote: > > I have made some code to produce two pwm's to let two led's fade in > > and fade out. > > It looks to work but the outputs are never been > > set. Am i missing somethin? > > The PIC used is a 16F685 and i am > using MPLAB IDE 8.30 as development tool. > > > > [code] > > movlw d'2' ; init slope counter > > movwf ACC_COUNT > > > > movlw 0x0F > > movwf CV545 > > movlw 0x03 > > movwf CV515 > > clrf PWM1A > > clrf PWM1B > > ; > > > ---------------------------------------------------------------------- > > MainLoop: > > > > F1A_Set: ; If B is on then fade out > > ; then fade A in else A in > > clrf SPEED1B ; turn off > > bcf DIR_UP,OUT1B > > bcf LIGHT_UP,OUT1B > > btfss DIR_UP,OUT1A ; if lights, nothing to do > > bsf LIGHT_UP,OUT1A ; next light this > > call DoLight1 > > F1B_Set > > clrf SPEED1A ; turn off > > bcf DIR_UP,OUT1A > > bcf LIGHT_UP,OUT1A > > btfss DIR_UP,OUT1B ; if lights nothing to do > > bsf LIGHT_UP,OUT1B ; next light this > > call DoLight1 > > goto MainLoop > > > > DoLight1: > > decfsz ACC_COUNT,f ; slope > > goto SpeedOn > > > > movf CV545,w ; load slope from CV > > movwf ACC_COUNT > > > > movf PWM1A,w ; all off? > > iorwf PWM1B,w > > btfss STATUS,Z > > goto DoPWM1A > > DoLight1A: > > btfss LIGHT_UP,OUT1A ; realy do lightA > > goto DoLight1B > > bcf LIGHT_UP,OUT1A > > bsf DIR_UP,OUT1A ; If so set max light > > movf CV515,w > > movwf SPEED1A > > DoLight1B: > > btfss LIGHT_UP,OUT1B ; realy do LightB > > goto DoPWM1A > > bcf LIGHT_UP,OUT1B > > bsf DIR_UP,OUT1B ; If so set max light > > movf CV515,w > > movwf SPEED1B > > > > DoPWM1A: > > movf PWM1A,w ; calc PWM acc/dec > > xorwf SPEED1A,w > > btfsc STATUS,Z > > goto DoPWM1B > > movlw 0x01 > > btfss DIR_UP,OUT1A > > movlw 0xFF > > addwf PWM1A,f > > DoPWM1B: > > movf PWM1B,w > > xorwf SPEED1B,w > > btfsc STATUS,Z > > goto DoLight1 > > movlw 0x01 > > btfss DIR_UP,OUT1B > > movlw 0xFF > > addwf PWM1B,f > > goto DoLight1 > > > > SpeedOn: > > clrf OUTPUT ; do PWM of outputs > > rrf TMR1H,w > > rrf TMR1L,w > > movwf TIMER > > bcf STATUS,C > > rrf TIMER,w > > btfsc TMR1H,1 > > iorlw 0x80 > > iorlw 0x0F > > > > movwf TIMER > > addwf PWM1A,w > > btfsc STATUS,C > > bsf OUTPUT,OUT1A > > movf TIMER,w > > addwf PWM1B,w > > btfsc STATUS,C > > bsf OUTPUT,OUT1B > > movf OUTPUT,W > > xorwf PORTC, W > > andlw (1< > xorwf PORTC, F ; > > > > movf PWM1A,w ; If either one is zero > > iorwf PWM1B,w > > btfsc STATUS,Z ; do it again > > goto DoLight1 > > > > movf CV518,w ; where doing PWM now > > xorwf PWM1A,w ; and keep doing so until > > xorwf PWM1B,w ; the value in CV518 is > > btfsc STATUS,Z ; reached > > return ; Light should be on > > goto DoLight1 > > [/code] > > > > Any help would be welkom. Regards > > > > Harry > > > -- > http://www.piclist.com PIC/SX FAQ & list archive View/change > your membership options at > http://mailman.mit.edu/mailman/listinfo/piclist > -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist