I have this project at work (can't really post the complete code)where I'm using the ECCP on a 12HV615 to output a PWM signal that changes the duty cycle with a button press. I had the chip blazing at 8MHz with no regard to current consumption. now I'm trying to cut the current. I changed to 4MHz, and I added a nap command while I wait for the button press. The nap command shuts down the PWM, so I can only nap when the duty cycle is zero. the thing is, it had no effect on the current consumption. Can anyone enlighten me?
here is (sort of )the code ...thanks PicmultiCalc!
Code:@ __CONFIG _CP_ON & _WDT_ON & _BOR_OFF & _MCLRE_OFF & _PWRTE_ON & _INTRC_OSC_NOCLKOUT & _IOSCFS_4MHZ CLEARWDT DEFINE OSC 4 ANSEL.... GPIO.... TRISIO.... array of pwm values.. set CPP duty cycle to zero.. 'SETUP and turn on PWM module for 20KHz, using a 4MHz clock CCP1CON = 001100 ' CCP1, PWM mode, single output PR2 = 49 ' 49 = 20KHz pwm frequency @4MHz and 1:1 prescaler T2CON = 000100 ' 1:1 postscaler, TMR2 on, prescaler is 1 Main: WHILE SWITCH_INPUT = 1 ; Wait here for the dim input to go low IF PWMvalue[state] = 0 THEN ; if the light is off, then TRISIO = 111111 ; set pins to high impedance CCP1CON = 000000 ; turn PWM off (resets ECCP module) T2CON = 000000 ; TMR2 off NAP 0 ; go into low power mode for about 18 milliseconds @ NOP ELSE TRISIO = 111000 ;turn outputs back on CCP1CON = 001100 ; CCP1 is on, PWM mode, single output T2CON = 000100 ; 1:1 postscaler, TMR2 on, prescaler is 1 ENDIF WEND blah blah blah debounce increment the state variable pull the new pwm value out of the array update the pwm wait for the switch to be released loop back to main




Bookmarks