Hello,
To make my design easier (I have an other solution with 2 external transistors) I use the ASM Sleep instruction. it works but the current cosumption is about 0.75 mA. I don't know what more and how to disable it to reach the 0.35µA of FIGURE 16-13: TYPICAL IPD vs. VDD (SLEEP MODE, ALL PERIPHERALS DISABLED of the data sheet for the 12F683. Pin_A3 is tied via a resistor to GND
Here my code:
; Push button perceuse version avec sleep
; Freq PWM 4 kHz
; rapport cyclique 50%, 75% et 100%
; PIN_A2 out PWM
; Utilisation de IOC pour sortir du mode sleep
; sleeep: le wake-up avec IOC se fait avec un "1",
include 12f683 -- target PICmicro
pragma target OSC INTOSC_NOCLKOUT
-- This program assumes the internal oscillator
-- is running at a frequency of 4 MHz.
pragma target clock 4_000_000 -- oscillator frequency
-- configuration memory settings (fuses)
pragma target WDT disabled -- watchdog
pragma target MCLR internal -- internal
pragma target CP ENABLED
pragma target brownout ENABLED
pin_A2_direction = output
pin_A5_direction = input
pin_A0_direction = output
pin_A1_direction = output
pin_A4_direction = output
OPTION_REG = 0b_1111_1111 -- ~GPPU disabled
WPU = 0b_0001_1111 -- pull up sur ttes les pin sauf la 5
enable_digital_io() -- disable analog I/O (even if none on the chip)
include delay_pat
include pwm_hardware
var bit push_B
var byte count_in = 0
pwm_set_frequency (4000)
var byte ratio
var bit Bouton is pin_a5
var bit led1 is pin_a0
var bit led2 is pin_a1
var bit led3 is pin_a4
var bit mem_on = 1
var bit mem_off = 1
INTCON_GPIE = 1 ; enables IOC
INTCON_GIE = false;-- Enables all unmasked interrupts false;: no interrupt
INTCON_PEIE = false -- Enables all unmasked peripheral interrupts
IOC_IOC5 = on
porta = 0 ; all out off
forever loop
; when pressing the button, I put pin_A5 high then I disable the input with mem_on = 0
; after the "debounce time of 50 ms, it set Push_B to 1
if Bouton & mem_on then mem_on = 0 mem_off = 1 delay_1ms(050) Push_B = 1 end if
; after rising edge push_B changes to 1, the counter "count_in" is incremented
if push_B Then count_in = count_in + 1 push_B = 0 end if
; various duty cycles an led are set
if count_in == 0 then pwm1_off() pin_a2 = off end if
if count_in == 1 then pwm1_set_dutycycle_percent(050) pwm1_on() led1 = 1 end if
if count_in == 2 then pwm1_set_dutycycle_percent(075) led2 = 1 led1 = 0 end if
if count_in == 3 then pwm1_set_dutycycle_percent(100) led3 = 1 led2 = 0 end if
; At the fourth push, all is stopped and the PIC goes in sleep mode and "count_in" set to 0
if count_in == 4 then pwm1_off() led1 = 0 led2 = 0 led3 = 0 count_in = 0 pin_a2 = 0
asm sleep
end if
;When the button is realised the input is again disabled for 200 ms. Push_B
; is set to 0 and mem_on is on to validate the next push.
if !Bouton & mem_off then mem_off = 0 mem_on = 1 delay_1ms(200) Push_B = 0 end if
end loop
Thanks
Patrick