How to put the msp430 to sleep for 12 seconds? - msp430

What's the best way to put the MSP430 to sleep for 10 seconds. Speed is not as important as low power usage.

Use a Timer.
Setup a timer with the right prescaler. preload it and make it overflow after 10 seconds.
Start the timer and put the CPU in low power.
In the timer ISR which is executed after 10 seconds, wake up the CPU.
And that's it.

Related

how to use esp32 ulp interrupt pulse counter and periodic wake up deepsleep mode

I am trying to measure power usage using dds353 kWh meter. This meter has a pulse output. I am interested in using the esp32 since I can periodically send the data over the internet to nodered dashboard.I am also very interested in using the esp32 in low power mode and periodically wake up to send data over mqtt. I have tried out examples from github using espressif idf but I would not mind an arduino equivalent. I would like to do hardware interrupt which when one of the rtc gpio pin goes high a counter is incremented while a seperate timer interrupt run and occasionally wakes up the main xtensia cores which fetches data from the rtc and sends it over. I have looked at the pulse counter examples and with my limited knowledge can not tell if the interrupts are triggered when the ulp is in sleep mode or only when it is on. I would really be glad if someone would show me how to basically use the ulp for counting pulses even when it is sleep mode and periodically wake up the main cores. I am ok with IDF or arduino examples
If you want to count pulses while in deep sleep youuse the ULP. Code on the ULP continues to execute when the board wakes up and goes to normal power mode. So when it is awake, it will still run the counter on the ULP processor unless you stop the ULP periodic wake up timer, ULP will keep waking up and running while the main CPU is active.
As you gave already checked with this example , it should be pretty close to what you need. The only difference seems to be that the example is set to wake up after a given number of pulses, rather than a fixed amount of time. However it should be easy to change that, by enabling deep sleep wake up from timer.For the Arduino you could check Some additional info:
ULP doesn't have GPIO interrupts. So you use deep sleep wake stub (small piece of code which runs immediately after deep sleep, prior to loading application from flash into RAM) you can increment the pulse counter variable, and go to sleep again. This way you can get low power consumption (~5uA) between pulses and moderate power consumption while running the wake stub (around 13mA), for a very short time.
So its up to you to experiment with your specific scenario.
You can use Pulse Counter(PCNT) feature in ESP32 to count the number of pulse in background, Understanding by using same you can able to do some periodic wake-up and read the count.. Its also possible to configure event when number of counts reached certain threshold and had lot of options,
For get information and available Interfaces and API's for Pulse Counter(PCNT) please follow below link, https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/peripherals/pcnt.html
Initially I faced lot of issue to make Pulse Counter(PCNT) work in Adrino IDE for ESP-32, After multiple attempt I make it working, And same sample code is uploaded in GitHub for reference. I have not use all the API's in the official documentation but but used few of them and are working..
I have created sample program for a water flow meter, there also we use to get pulse which needs to count to measure the water flow rate, understanding simile to kWh meter.
GitHub Sample code Path:- https://github.com/Embedded-Linux-Developement/Arduino_Sample_Programs/tree/main/ESP_32/Water_Flow_Pulse_counter_WithOut_Interrupt_Using_PCNT
I have not placing the code here, because its there in GitHub and not directly for the asked question, but simile one and can use it. Its a working code I tested in HW.
Hopes Its helpful,
Regards, Jerry James

SAM4S - Is DMA determinist in time ?

I'm using the DMA (described as PDC in the datasheet) of SAM4SD16C with USART 0 peripheral.
I've set a timer which generates a interrupt each ms. Each 5 ms a data transfert should be performed via DMA.
An other interrupt should occur when TXEMPTY flag is set.
To see when the transmission starts and ends I toggle an Ouptut and watch it on oscilloscope. And then I realized that the end of reception is varying in time by 20 µs (my main clock is 120MHz)... Which in my project is not acceptable. Meanwhile, the start of transmission is 100ns precise, so there is no problem concerning this point.
I'm wondering if there is a way to have a better control on DMA time transfer.
As discussed in comments above, the imprecision of End Of Reception instant is due to baudrate value. This imprecision is around the baudrate period and probably an additional bus idle time.

Wait for OpenCL kernel termination, but only during some time

To wait for kernel termination on the host side I can do this:
error = clEnqueueNDRangeKernel(..., &event);
CHECK_ERROR(error);
clWaitForEvents(1, &event);
But is there a way to precise some maximal time of waiting? That is, if my kernel is not finished after, let's say, 10 seconds I'd like to continue, but if it takes only one second of execution I don't want to wait for the 9 remaining seconds.
There is no way to wait only for a given amount of time, however you can:
Check if the event has finished every N seconds via clGetEventInfo() and a loop.
Use clSetEventCallback() to define a function that will be called when the event completes. Sleep the current thread for 10 seconds, and make the event callback wake the thread if it finishes quicker than 10 seconds.

Wake up Arduino in sleep mode after x hours [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 2 years ago.
Improve this question
I need to put an Arduino to sleep mode to save battery, but after x hour (A choice that makes the user), I need that the Arduino wakes up, do some action, and then goes to sleep again. How can I do it? I see that the sleep mode can be interrupt by Interrupt, but I need that the interrupt is trigger not by a pin but by the time. Any suggestion?
Thanks in advance!
The answer to your question depends on how much low power you need and which time precision you need. Achive 200nA sleep current requires some work and time precision is a compromise with low power.
However, here are some clues:
Use an external RTC module able to generate an interrupt at some precise moment
Use an external 32kHz Xtal to clock timer2 asynchronously and generate interupt to wake up from "power-save" sleep mode
Use the internal watchdog timer in interrupt and reset mode to wake up from "power-down" mode. You will wake up every 8s but for very short duration if the code is optimized.
The last solution seems most appropriate for some basic demo. With a good code you will achieve honorable results. And do not forget to read "Minimizing Power Consumption" section of the MCU datasheet.
EDIT
how much more current I consume if the Arduino wakes up every 8 seconds?
There is a way to calculate it?
Too calculate the average current (I would say estimate) read datasheet at section "atmega328P typical characteristics"
#5V 8MHz the consumption is about 5.5mA,
in power down #5V with watchdog 6.5µA.
With about 1ms active every 8s you will achieve 7.2µA mean.
Note that the board consumption is not only the MCU on Arduino board. With an Arduino I don't know how much you will globally consume but it will be more than my calculation. To achieve 200nA stated in datasheet, you will need to do your own board and use external low power watchdog...
And second: the AtMega will ruin faster if wakes up every 8 seconds?
An AtMega does not have ageing issues. It can run constantly for 20 years without issues (except if you use EEPROM or flash self-programming).

Does Arduino's clock (millis) continue counting in the background during interrupts?

I have a quick question which apparently isn't said online from what I've read: I know millis() on an Arduino doesn't change during a custom interrupt, but does the associated timer still counts in the background?
My program is time-sensitive and I would like to know if I should increase its value (how?) each time one of my interrupts is handled so that the main program's clock doesn't drift.
Thanks in advance,
Regards,
Mister Mystère
The CPU-internal timer will count even when interrupts are disabled. BUT when the timer overflows an interrupt is generated which will increment some counter in the library. If that interrupt is blocked for a long time ... then you will have a drift.
The CPU timer is hardware and not affected by any interrupt flags. Once it overflows the overflow bit is set / an interrupt is triggered. If interrupts are blocked at that time this interrupt will be queued. The queue size is 1, that is your must allow interrupts before the next interrupt is triggered. Since the timer overflows roughly once per millisecond you will need to ensure that you never block interrupts for longer than ~1ms.
Anyway you will have a drift since the Arduino's clock is not that precise at all. See my experiment on crystal deviations.

Resources