CROSS Technical Documentation User Manual and Technical Doc.
INFN Milano Bicocca
Loading...
Searching...
No Matches
The Power down

Power Down operation

SUMMARY:

Power Down introduction



μ-controller power down it's a feature that allows to mitigate disturbances by stopping μ-controller clock. In addition a small save is also obtained in ower consumption. Power Down implementation in our fw is quite flexible: it can be set ON or OFF and the time to wait before power down is active can be also set.
The variable that account for the power down wait is POWER_DOWN_TEMPO_ATTESA. It is reset after any wake up and at startup. It is increased within SysTick_Handler() and is a multiple of 10 ms. Maximum elapsed time before power down is set by the user through POWER_DOWN_MAX_ATTESA. This is done in the main() :

274 //COMANDI PER IL POWER_DOWN
275 if (POWER_DOWN_TEMPO_ATTESA >= POWER_DOWN_MAX_ATTESA) // Viene incrementato tempo finch\'e non arriva a quel valore
276 {
277 per_non_ripetere = 255;
279 if((flag_power_down == true) && POWER_DOWN_ABILITA_CONTEGGIO) // Se il flag \'e true, viene attivata la modalit\'a Power Down
280 {
281 // Il micro entra nella modalit\'a Power-down
282 // POWER_DOWN_ABILITA_CONTEGGIO=0;
287// Pwd_Paolo();
288 }
289 }
void LED_remote_ON_OFF(void)
LEDs can be set ON/OFF from remote.
Definition: Led.c:161
void LED_accendi_spegni(uint8_t LED, uint8_t accendi_1_spegni_0)
This function turns ON or OFF any of the selcted LED.
Definition: Led.c:123
#define LED_RED
Definition: Led.h:10
#define spegni
Definition: Led.h:13
#define LED_GREEN
Definition: Led.h:11
volatile uint32_t POWER_DOWN_MAX_ATTESA
upper limit for POWER_DOWN_TEMPO_ATTESA
Definition: Power_down.c:118
volatile uint32_t POWER_DOWN_ABILITA_CONTEGGIO
Power down couter and anable is set if this variable is true.
Definition: Power_down.c:120
void PowerControl_PowerDown(void)
Power down managing function.
Definition: Power_down.c:274
volatile uint32_t POWER_DOWN_TEMPO_ATTESA
Counter to wait for power down, multiple of 10 ms.
Definition: Power_down.c:116
bool flag_power_down
if flag_power_down is true the u-controller goes in power down after a while

As it can be seen, power down is enabled or not in relation to the 2 boolean variables POWER_DOWN_ABILITA_CONTEGGIO and flag_power_down. The first one, POWER_DOWN_ABILITA_CONTEGGIO, is set false by the fw whenever there is an action into operation. The switch flag_power_down is instead set by the user with the proper instuction, se below.
The function that manages the poower down, invoked above, is PowerControl_PowerDown().

Power down managing



Power down to take place needs of a few steps:

  • Preparation of the peripheral which will be sensitive to wake up;
  • Turn off of all the peripherals that could inhibit the power down to start;
  • turn off of the PLL and set the clock to a default;
  • Start of power down;
  • Operations to be down at wake up: clock, peripherals,...


Our μ-controller has the possibility to be waked-up from the activity on the CAN bus line. However, we encontered some difficulties in exploiting that feature and have used in previous μ-controllers the wake-up from the pin. For doing that the CAN is first disabled, than the receiving pin is set as GPIO input, and enabled as interruput from wake-up, as listed here:

303#ifdef power_down_conEINT3
304//Questo \'e il powerdown con wake col pin EINT3, di Paolo. L'laternativa sempre valida
305
306 // All the RXD pin reconfigurations are implemented as C preprocessor macros
307 status = CANdrv ->PowerControl(ARM_POWER_OFF); //AL risveglio serve per resettare tutti i registri, altrimenti
308 status = CANdrv -> Uninitialize();
309// NVIC_DisableIRQ(CAN_IRQn);
310 PIN_Configure(CAN_RD_PORT, CAN_RD_BIT, PIN_FUNC_0, PIN_PINMODE_TRISTATE, PIN_PINMODE_NORMAL); // Configure pin as GPIO
311 NVIC_DisableIRQ(EINT3_IRQn); // EINT3 could have been enabled somewhere else
312 CAN_INT_F_Enable; // Enable GPIO falling edge interrupt
313 CAN_INT_Clear; // Clear GPIO interrupt
314 NVIC_SetPriority(EINT3_IRQn,31);
315 NVIC_SetPriority (SysTick_IRQn, 29); /* set Priority for Systick Interrupt */
316 NVIC_ClearPendingIRQ(EINT3_IRQn);
317 NVIC_EnableIRQ(EINT3_IRQn);
318 fuffa=0;
319
320//Occorre ricordare che la funzione che viene chiamta dall'interupt \'e
321// EINT3_IRQHandler();
322#endif
323
324 I2CAdrv->PowerControl (ARM_POWER_OFF); // Terminate any pending transfers, reset IRQ/DMA, power off peripheral
325 I2CAdrv->Uninitialize ();
326 I2CBdrv->PowerControl (ARM_POWER_OFF); // Terminate any pending transfers, reset IRQ/DMA, power off peripheral
327 I2CBdrv->Uninitialize ();
328 SPIdrv->PowerControl (ARM_POWER_OFF); // Terminate any pending transfers, reset IRQ/DMA, power off peripheral
329 SPIdrv->Uninitialize ();
ARM_DRIVER_CAN * CANdrv
Definition: Can.c:333

As it can be seen, the other communication peripherals used are disabled, too.
The next important step is to disable the PLL of the clock:

333 //The SCR (System Control Register) register controls features of entry to and exit from low power modes
334 //In order to set the Power Down Mode in the PCON register, it's necessary set to 1 the SLEEPDEEP bit in the scr register
335 SCB->SCR |= 4; //(1UL << 2); // Set SLEEPDEEP, il tipo di powerdown
336 LPC_SC->PCON = 0x9; // 1+8: 1=l'esecuzione di WFI o WFE inizia il power down, se SLEEPDEEP=1, 8=il brown-out \'e disabilitato e non consuma potenza
337
338 //If PLL0 (the main pll) is enabled and connected before etering Deep Sleep or
339 //Power-down modes, it will remain enabled and connected afeter the chip enters
340 //Deep Sleep or Power-down mode, causing the power consumption to be higher.
341 //The code below disable and disconnect PLL0 (See Errata sheet Rev. 10.2)
342
343if(mio_PLL0_SETUP){
344 LPC_SC->PLL0CON &= ~(1<<1) ; //Disconnect the main PLL, il PLL0
345
346 //A feed sequence must be written to the PLL0FEED register in order for changes
347 //to the PLL0CON and PLL0CFG registers to take effect.
348 //The feed sequence is:
349 //1) write the value 0xAA to PLL0FEED
350 //2) write the value 0x55 to PLL0FEED
351
352 LPC_SC->PLL0FEED = 0xAA; //Feed
353 LPC_SC->PLL0FEED = 0x55; //Feed
354
355 while ((LPC_SC->PLL0STAT & (1<<25)) != 0x00); //Wait for PLL0 to disconnect
356
357 LPC_SC->PLL0CON &= ~(1<<0); //Turn off PLL0
358
359 LPC_SC->PLL0FEED = 0xAA;
360 LPC_SC->PLL0FEED = 0x55;
361
362 while ((LPC_SC->PLL0STAT & (1<<24)) != 0x00){} //Wait PLL0 to shut down
363 }

Finally, the μ-controller is ready to sleep:

370 if( ( CoreDebug ->DHCSR & 1 )==0 ){ // questo per non fare pasticci se c'e' connesso il debugger
371 __WFI(); //Sonno... (WFI sta per Wait For Interrupt)
372 }else{
373// CANActivity_IRQHandler_mio();
374// while(riaccendi_tutto==0);
375// CANActivity_IRQHandler(); //Al risveglio del CAN viene chiamata questa funzione registrata
376 while(fuffa==0){
377 __NOP();
378 }
379 }

The switch on CoreDebug ->DHCSR is done to avoid conflict during the debug phase, if the debugger is connected to the JTAG.

Wake-up managing


The function EINT3_IRQHandler() is called at the wake-up, when the control room starts the activity on the CAN bus. The first action is to restor the pins dedicated to CAN and the shutting down of the waking interrupt pin in the function WakeResetCAN():

395void WakeResetCAN (void)
396{
397 CAN_INT_F_Disable;
398 CAN_INT_Clear;
399 NVIC_ClearPendingIRQ(EINT3_IRQn);
400 NVIC_DisableIRQ(EINT3_IRQn);
401 PIN_Configure(CAN_RD_PORT, CAN_RD_BIT, CAN_RD_FUNC, PIN_PINMODE_TRISTATE, PIN_PINMODE_NORMAL);
402
403}
void WakeResetCAN(void)
CAN pins restoring.
Definition: Power_down.c:395

Finally the clock and all the communication peripherals are re-activated in CANActivity_IRQHandler_mio():

210 void CANActivity_IRQHandler_mio (void){
211
212#ifdef power_down_conCAN
213 //Queste 3 istruzioni sono necessarie al risveglio
214 LPC_SC->CANSLEEPCLR|=2U; //Il clock viene ri-dato al CAN1
215 LPC_CAN1->MOD &=~(1<<4); //SCrivendo 0 in questo bit si ritorna al normal mode
216 LPC_SC->CANWAKEFLAGS|= 2U; //Reset dell'avvenuto risveglio
217 LPC_CAN1->IER &= ~(1<< 4); //Spegnamo l'interruput da wakeup del CAN
218 NVIC_DisableIRQ(CANActivity_IRQn); //Via anche la chiamata
219#endif
220
221 System_init();
222
223 I2C_1_Initialize(); // Viene inizializzata la periferica I2C_A
224 I2C_0_Initialize(); // Viene inizializzata la periferica I2C_B
226
227 // Disable CANActivity interrupt
228 LPC_SC->PCON &=~ 0x01; // Reset powerdown mode to idle mode
229 SCB->SCR &=~ (1UL << 2); // Reset SLEEPDEEP
230 CAN_Inizialize(); // Viene inizializzato il CAN
231 can_clock= CANdrv->GetClock();
232// NVIC_EnableIRQ(CAN_IRQn);
233 CANdrv->Control(ARM_CAN_ABORT_MESSAGE_SEND, tx_obj_idx);
234 LPC_CAN1->MOD |=1; //Si annullano tutte le possibili azioni pendenti
235 LPC_CAN1->GSR &= ~CAN_GSR_TXERR_Msk; // Azzeriamo gli errori di trasmissione
236 LPC_CAN1->MOD &=~1; //Si riabilita il CAN
237 uint32_t LPC_dummy= LPC_CAN1->ICR;
238 SystemCoreClockUpdate();
239 rx_msg_info.id = ARM_CAN_EXTENDED_ID(indirizzo_CAN_della_scheda); // Viene settato l'indirizzo esteso per il messaggio da ricevere
240 fuffa=1;
241}
uint32_t tx_obj_idx
This is the variable which resembles the flags from the communication.
Definition: Can.c:323
unsigned int indirizzo_CAN_della_scheda
Per ora lo assegnamo cos\i l'indirizzo della scheda.
Definition: Can.c:335
void CAN_Inizialize(void)
The CAN initialization function.
Definition: Can.c:433
void I2C_0_Initialize(void)
The I2C_0 initialize.
Definition: I2C_0.c:369
void I2C_1_Initialize(void)
The I2C_1 initialize.
Definition: I2C_1.c:106
void CANActivity_IRQHandler_mio(void)
Peripherals Wake-up.
Definition: Power_down.c:210
void SPI_Inizialize(void)
SPI is initialized here. Its ise t at 8 bits and 100 KHz, as default.
Definition: Spi.c:205
See also
The instruction over the CAN to set the Power Down parametrs is instr_Shut_Down_ON_OFF.