Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

pic16f628a sleep mode

Status
Not open for further replies.

gatoulisss

New Member
hello everyone,
im using an pic16f268a microcontroller to build an security alert system witch is powered with 9v battery the problem is that after 3-4 days that my system is working the battery is going off...
after a little search ifind out about the sleep mode but because im new to this i dont know how to use it.
any help? how i can wake and sleep my processor? can i wake it up when a button is pressed or something like this happens?

thank you very much!
 
Yes, you can wake up on a button press or other inputs provided they're connected to pins that support "interrupt on change".

What language are you using?
 
If you google "microchip low power tips" you will find a few PDFs that microchip have produced with good information.

Mike.
 
My question is why are we only running it on batteries? Most security systems I've seen use wall power for primary power with battery backup.
 
im using it in place with no power source thats why i want 9v battery also the size matter so i cant put bigger battery
so, how i can make my microcontroller sleep until for example one of the sensors become from 0 to 1?? im using mikroC to program the microcontroller.
 
there are three sensors with three pull up resistors one on-off button with one pull up resistor one buzzer the pic and the lm7805 regulator with two capacitors
 
Well for a start, dump the LM7805 regulator - that's wasting huge amounts of power. Assuming you need to use a 9V battery?, use a switch-mode regulator instead (you can get tiny adjustable ones ready made from Bangood for very little money).

What value are the pull-up resistors, and what are the 'sensors'? - if you're minimising current, you need to design those accordingly.

A VERY simple way of reducing current is to reduce the clock speed (your speed requirements are very low) - and the 628 has an internal 32KHz oscillator you could use.
 
the sensors are magnetic ones like the ones we use in the doors to know when is open or closed
the value of the resistors is 10k also because im using the delay so the alarm will ring after 3sec i dont know if i make 32khz of the clock speed will be usefull
**broken link removed** this part for example will do the job?
or this one
**broken link removed**

also i have the 78L05 regulator (sot 89) is this also wasting so much power?

thank you!
 
Last edited:
the sensors are magnetic ones like the ones we use in the doors to know when is open or closed
the value of the resistors is 10k also because im using the delay so the alarm will ring after 3sec i dont know if i make 32khz of the clock speed will be usefull

You simply recalculate the delays - or as you're using C presumably simply telling the compiler the clock speed will do so automatically?.

BTW, the low speed internal oscillator is 37KHz, not 32KHz - and using it will greatly reduce consumption.

Presumably you mean simple reed switches?, activated with magnets? - in which case they are closed when the doors are closed - so each closed door is wasting 0.5mA with 10K pull-ups. Changing the 10K's to 100K's will reduce that waste to 10% (0.05mA).

**broken link removed** this part for example will do the job?
or this one
**broken link removed**

also i have the 78L05 regulator (sot 89) is this also wasting so much power?

Yes, it's wasting almost 50% as it's an analogue regulator - so simply replacing this with a switchmode regulator would almost double your battery life.

Using three AA's in series would avoid the need for a regulator at all, and offer a MUCH better cost to power ratio.
 
You simply recalculate the delays - or as you're using C presumably simply telling the compiler the clock speed will do so automatically?.

Yes, it's wasting almost 50% as it's an analogue regulator - so simply replacing this with a switchmode regulator would almost double your battery life.

Using three AA's in series would avoid the need for a regulator at all, and offer a MUCH better cost to power ratio.

**broken link removed** this part for example will do the job?
or this one
**broken link removed**

the one is switch mode regulator
 
so lets tell i buy one of these, (i prefer to use the ones i send you so i can use them even in smaller projects in my own board because with one of these i will use 2 boards)

then how i could put my pic into sleep mode (so i can save even more power) and wake it up by change the sensor situation from 0 to 1?
 
If you are running on very low power, you want a regulator that takes little current. It is usually called "low quiescent current".

The voltage regulator wastes power in two ways. Firstly, in the current that it takes all the time, even with no load, called the quiescent current. Secondly, linear regulators also loose power that is the voltage dropped multiplied by the current taken.

A switch-mode regulator reduces power lost at larger loads, as the output current can exceed the input current. However, for very low load currents, the switch mode regulator will usually have a worse quiescent current.

If you get the processor to go to sleep, the current taken will be tiny, so you will probably take less power from the battery with a low quiescent current linear regulator than you would with a switch mode regulator.

At high powers, a linear regulator will never be more efficient than 5/9 = 56%, while a switch mode regulator can be a lot better.
 
so lets tell i buy one of these, (i prefer to use the ones i send you so i can use them even in smaller projects in my own board because with one of these i will use 2 boards)

It's not really a 'board', it's more a component - they are tiny, and easily mount on your existing PCB. Bear in mind if you build your own you need to add all the other components as well, inductor, capacitors and diodes etc.

then how i could put my pic into sleep mode (so i can save even more power) and wake it up by change the sensor situation from 0 to 1?

The datasheet has a section on 'waking from sleep mode via interrupts'.

However, I would suggest you upgrade to the 16F1827 which is considerably cheaper, and has a far higher spec. In particular it's better for low power consumption (so called nano-watt technology), and also has much improved 'wake up via I/O interrupt' capabilities (you can do it via individual pins, and by either rising, falling, or changing).

I've used this chip in a GSM based device, in a kind of specialised 'alarm' function, and required battery live is five years or so (depending on number of activations).
 
It's not really a 'board', it's more a component - they are tiny, and easily mount on your existing PCB. Bear in mind if you build your own you need to add all the other components as well, inductor, capacitors and diodes etc.

would be this a good choice for example? it needs only two capacitors (the picture)

also if my code look like this (its just an example to understand how to use sleep mode)

Code:
void main() {
osccon=0x60;
ansel=0;
TRISB.F7 = 0;        //buzzer output
TRISA.F0 = 1;       // one of the sensors
PORTB.F7 = 0;
for(;;){

if   (PORTA.F0==0) {
  delay_ms(3000);       //wait some time before th alert
  while(PORTA.F0==0)
  {
    PORTB.F7 = 1;           //alert

  }
}
else {
PORTB.F7 = 0;
}
}
}

how i could put my microcontroller in sleep mode and wake it up when a change to status of the sensor happens?

thank you a lot!
 

Attachments

  • Untitled.jpg
    Untitled.jpg
    139.4 KB · Views: 323
I didn't use 'sleep' in this example, but this is how I set up the individual I/O interrupts on my 16F1827.

Code:
// setup PortB interrupt 
    INTCONbits.IOCIE = 1;               // enable interrupt on PORTB change global
    IOCBPbits.IOCBP4 = 1;               // when input is pressed, enter the ISR
    IOCBNbits.IOCBN5 = 1;               // when input is released, enter the ISR
    IOCBPbits.IOCBP0 = 1;               // when Mode is pressed, enter the ISR
    IOCBPbits.IOCBP2 = 1;               // when Range is pressed, enter the ISR
    IOCBNbits.IOCBN7 = 1;               // when ON/OFF is pressed, enter the ISR

Using different interrupts for rising and falling edges.
 
I didn't use 'sleep' in this example, but this is how I set up the individual I/O interrupts on my 16F1827.

Code:
// setup PortB interrupt
    INTCONbits.IOCIE = 1;               // enable interrupt on PORTB change global
    IOCBPbits.IOCBP4 = 1;               // when input is pressed, enter the ISR
    IOCBNbits.IOCBN5 = 1;               // when input is released, enter the ISR
    IOCBPbits.IOCBP0 = 1;               // when Mode is pressed, enter the ISR
    IOCBPbits.IOCBP2 = 1;               // when Range is pressed, enter the ISR
    IOCBNbits.IOCBN7 = 1;               // when ON/OFF is pressed, enter the ISR

Using different interrupts for rising and falling edges.
so do you know what i have to do so i can enter and wake up from sleep mode?

thank you!
 
so do you know what i have to do so i can enter and wake up from sleep mode?

thank you!

Same as in assembler, you simply issue the 'sleep' command - when an interrupt occurs the processor will wake up.

In my example below the processor is woken by a timer interrupt every second, which updates a real time clock, and checks to see if the reed switch is activated - otherwise it goes back to sleep. This gives something like five years battery life.

Code:
; ****************** wait for unit to be turned on via reed switch ******************

Wait_Reed
                sleep                        ; wake every second and check switch
                btfsc    PORTA, Reed            ; wait for Reed switch activation
                bra        Wait_Reed
                call    Delay50                ; debounce delay
                btfsc    PORTA, Reed            ; check Reed switch still activated
                bra        Wait_Reed
                call    LED_ON                ; turn LED ON to show activation
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top