Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Pinguino wake-up from sleep mode - help
07-09-2012, 10:52 PM,
#1
Pinguino wake-up from sleep mode - help
Hi,
How wake-up pinguino from sleep every second for a seconds clock increment?
If i use ontimer pinguino remains on sleep mode until reset or change INT pin.
Any sugestion or code example plz ?

Microdev
Reply
08-09-2012, 01:17 AM,
#2
RE: Pinguino wake-up from sleep mode - help
(07-09-2012, 10:52 PM)microdev Wrote: Hi,
How wake-up pinguino from sleep every second for a seconds clock increment?
If i use ontimer pinguino remains on sleep mode until reset or change INT pin.
Any sugestion or code example plz ?

Microdev

Have tried any code before? If so, can you paste it so we can read it, and also please specify the type of pinguino and IDE that you have, so we can better help you.
mi Blog MicroEmbebidos (PINGUINO,PIC,STM32F,ATMEL)
http://microembebidos.wordpress.com/
Reply
08-09-2012, 01:49 AM,
#3
RE: Pinguino wake-up from sleep mode - help
Code:
u8 s  = 0;
u8 m  = 0;
u8 h = 0;

void tick()
{
    s++;

    if (s > 59)
    {
        s = 0;
        m++;

        if (m > 59)
        {
            m = 0;
            h++;

            if (h > 23)
            {
                h = 0;
            }
        }
    }    
}
void wake_up()
{
    lcd.setCursor(4, 0);
    lcd.print("WAKE-UP");
}
void setup()
{
    pinMode(14, INPUT);
    lcd.pins(8, 9, 25, 26, 2, 3, 4, 5, 6, 7);
    lcd.begin(2, 0);
    OnTimer1(tick, INT_MILLISEC, 1000);
    OnChangePin0(wake_up, INT_FALLING_EDGE);
}
void loop()
{
    lcd.setCursor(4, 1);
    lcd.printf("%02u:%02u:%02u", h, m, s);
    if(digitalRead(14)==0) {
        lcd.setCursor(4, 0);
        lcd.print("SLEEP");
        sleep();        
    }
    delay(100);  
}

Pinguino is from SVN. it was downloaded yesterday; rev 558 I suppose.

I want to wake-up and do tick() every second. I don't want to use an external clock device because this sleep mode will operate only on main power faults (12 hours max) and the pinguino will be powered from a 3v battery source, depends on the finnal power consumtion (nA I hope) of the circuit.
The clock isn't necessary to be very accurate; even a error of 10 minutes on a month is not a problem.
Reply
08-09-2012, 11:37 AM,
#4
RE: Pinguino wake-up from sleep mode - help
Hi

I already used a RC timer to wake up a Pinguino from sleep state.
OnTimer interrupt is not really useful for long time ( 1 second ) because and interrupt is generated not only every second due to the prescaler.

I made a little schematic for your which should suit for 1 second.

Connect this circuit to an OnChange pin of Pinguino.
Just charge the capacitor:
digitalWrite(cap_pin,1);
for ( i=1;i<10000,i++);
digitalWrite(cap_pin,0);

the capacitor is charged through the 330 ohms resistor ( this resistor is used to limit the output current of the pin because the capacitor is a short circuit when it is discharged )
when the capacitor is charged, it starts to discharge through the 330 and 100k resistor.
When the voltage is lower than the voltage level of the input Pin - 0,6V ( diode ), an interrupt is generated.
Take care to charge again the capacitor at the end of you interrupt treatment.
You can select the time with the 100k resistor.

Have fun
Jean-Pierre


Attached Files Thumbnail(s)
   
Reply
08-09-2012, 12:13 PM, (This post was last modified: 10-09-2012, 10:33 PM by microdev.)
#5
RE: Pinguino wake-up from sleep mode - help
Hi

Interesting idea but are two problems.
That for loop for charge the capacitor takes too long (10000) and the idea is to minimize time on wake-up.
In addition to the above requirements I want to use a lower frequent oscilator clock when the power is down and the device uses sleep and wake-up mode (125 kHz INTOSC or use a 4MHz external and use prescaler and postscaler between normal mode and sleel-wake-up mode).
The second problem is that I'm not shure if the time circuit RC provide a accurate one sec interval and tuning this will be very hard.

I read PIC18F4550 datasheet and more other post on the internet and I'm not really sure if timer 1 still operate on sleep mode. Tend to think it does not work if an external osc2 is not used and for that I want to wake-up every second. If wake-up every second (or often, I count this) without external osc2 is not possible how can I use timer1 with external osc? I tried _t1con = T1_OFF | T1_16BIT | T1_PS_1_8 | T1_RUN_FROM_ANOTHER | T1_OSC_OFF | T1_SYNC_EXT_OFF | T1_SOURCE_EXT; on interrupt.c and this code not increment even in normal mode (sure with external 32 khz osc connected ).

Code:
byte hours,mins,secs;
void setup()
{
// configure TIMER 1 to be used as RTCC
TMR1H=0×80;
TMR1L=0;
T1CON=0b00001111;

// init current time
hours=12;
mins=0;
secs=0;

// init interrupt for RTCC module
PIE1bits.TMR1IE=1;
INTCONbits.PEIE=1;
INTCONbits.GIE=1;

  lcd.pins(8, 9, 25, 26, 2, 3, 4, 5, 6, 7);
        lcd.begin(2, 0);
}

// timer 1 is interrupt driven
void UserInterrupt()
{
TMR1H=0×80;
PIR1bits.TMR1IF=0;
secs++;
if (secs==60)
{
secs=0;
mins++;
if (mins==60)
{
mins=0;
hours++;
if (hours==24) hours=0;
}
}
}

void loop()
{
  lcd.setCursor(4, 1);
    lcd.printf("%02u:%02u:%02u", hours, mins, secs);
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)