Bathini, I haven't looked really closely, but at just a glance, I don't see where you call the switch reading routine. This may be why it isn't working if you're going to get the duty cycle update from the switches. Jim -----Original Message----- From: piclist-bounces@mit.edu [mailto:piclist-bounces@mit.edu] On Behalf Of bathini Sent: Thursday, February 05, 2009 12:19 PM To: piclist@mit.edu Subject: Re: [PIC] PWM help for PIC16F88 Hello I have changed to a PIC16F628 due to its simplicity and I have the following code. Again, I am trying to simulate PWM signal out of RA0. I want to change the duty cycle by changing the 4 bits input to the PIC and that is why I have RB0 and RB1 for switch input. I am going round circles with this one.(3.5 weeks) Please help and thanks. Bathini PS Simulating on MPLAB ; ; 4-bit PWM for PIC16F628A or PIC16F627A ; ; ; RA0 - PWM out to motor ; RB0 - Switch input, increment duty cycle ; RB1 - Switch input, decrement duty cycle. ; ; Connect switches between I/O pin and Vss ; ; IFDEF __16F628A #include "p16f628a.inc" ENDIF IFDEF __16F627A #include "p16f627a.inc" ENDIF __CONFIG _CP_OFF & _WDT_OFF & _BOREN_OFF & _PWRTE_ON & _INTOSC_OSC_NOCLKOUT & _MCLRE_ON & _LVP_OFF errorlevel -302 ; suppress banksel warning messages cblock 0x70 ;0x70-0x7F common to all banks save_W ;0. save W during interupt save_Status ;1. save STATUS during interupt save_PCLATH ;2. save PCLATH portAcopy ;3. working variable holds data to write to PORTA period ;4. period counter variable duty ;5. duty cycle loop counter variable dutyReload ;6. duty cycle variable switches ;7. switch state variable temp ;8. temp variable used in switch functions endc ; Define port bit use ;----------------------------- pb.pwm equ 0 ; pwm output pb.swinc equ 0 ; duty cycle increment switch pb.swdec equ 1 ; duty cycle decrement switch ; Define constants ;----------------------------- Cperiod equ .15 ; (0-15 = 16 levels or 4-bits) org 0x000 ;RESET VECTOR goto startup ;goto to startup code on reset ; Initialise peripherals and registers at startup ; startup movlw 0x07 movwf CMCON ;disable comparator movlw 0x00 movwf portAcopy call output banksel OPTION_REG movlw ~(1< > The simulator in MPLAB seems to work fine. Why not use that? > > I routinely use PWM on the F88. > > --Bob > > On Fri, Jan 23, 2009 at 9:53 AM, bathini wrote: >> Hello Friends >> >> I am new to PICs and wanted to know how to simulate a PWM using 4bits >> as input or a code I can learn from this? I want to simulate a >> PIC16F88, and also do not know which simulation software to use. >> Thanks >> >> Bathini >> -- > > -- View this message in context: http://www.nabble.com/PWM-help-for-PIC16F88-tp21628310p21857830.html Sent from the PIC - [PIC] mailing list archive at Nabble.com. -- 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