Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Revision 1:0f0c1a9a174a, committed 2019-05-10
- Comitter:
- punkisnail
- Date:
- Fri May 10 05:51:35 2019 +0000
- Parent:
- 0:18409537564c
- Commit message:
- commit 1, pulse test using wait_us
Changed in this revision
diff -r 18409537564c -r 0f0c1a9a174a SoftPWM.lib --- a/SoftPWM.lib Sat Mar 30 06:37:35 2019 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -https://os.mbed.com/users/komaida424/code/SoftPWM/#7918ce37626c
diff -r 18409537564c -r 0f0c1a9a174a main.cpp
--- a/main.cpp Sat Mar 30 06:37:35 2019 +0000
+++ b/main.cpp Fri May 10 05:51:35 2019 +0000
@@ -4,221 +4,94 @@
*/
#include <mbed.h>
-#include "SoftPWM.h"
-
-#define DUTY_CYCLE 0.55f
-
-#define MAX_INTENSITY 70
-
-SoftPWM LEDR(p2);
-SoftPWM LEDG(p4);
-SoftPWM LEDB(p3);
-
-DigitalOut VEN_3V3B(p25);
-DigitalOut BOOST_EN(p14);
-PwmOut BOOST_PWM(p16);
-
-DigitalOut HB_CH1(p6);
-DigitalOut HB_CH2(p7);
+#define CH_INIT 0
+#define CH_BOOST_START 1
+#define CH_BOOSTING 2
+#define CH_POST_BOOST 3
+#define CH_WAIT_200MS 4
+#define CH_WAIT_800MS 5
-InterruptIn SW_ONOFF(p15);
-InterruptIn SW_MODE(p17);
-InterruptIn SW_PLUS(p13);
-InterruptIn SW_MINUS(p19);
+Serial pc(p6, p8);
-Ticker stimTicker;
+DigitalOut led1(LED1); // Used to indicate boost state to user
-volatile bool flip_power = false;
-volatile bool low_power = false;
-
-int intensity = 0;
+DigitalOut ch1(LED4);
-volatile bool stim_mode = false;
-volatile bool stim_active = false;
-volatile bool stim_progress = true;
-short stim_count = 0;
+Timeout chStateTimeout;
+
+Timer t;
-void flip_ONOFF() {
- flip_power = true;
-}
+volatile bool ch_progress = false;
+volatile bool ch_boost_done = false;
-void flip_MODE() {
- if (!low_power && !stim_mode) {
- stim_mode = true;
- }
-}
-
-void flip_PLUS() {
- if (!low_power && !stim_mode) {
- if (intensity < MAX_INTENSITY) intensity++;
- }
+// -----------------------------------------------------------------------------
+void timeoutHandler() {
+ ch_progress = true;
}
-void flip_MINUS() {
- if (!low_power && !stim_mode) {
- if (intensity > 0) intensity--;
- }
-}
-
-void stimProgress() {
- stim_progress = true;
-}
-
-void stimulate() {
- // DAC = intensity
- HB_CH1 = 1;
- HB_CH2 = 0;
-
- wait_us(100);
-
- HB_CH1 = 0;
- HB_CH2 = 1;
-
- wait_us(100);
-
- HB_CH1 = 0;
- HB_CH2 = 0;
- // DAC = 0
-}
-
-void startStimProcess() {
- stim_active = true;
- stim_count = 0;
- BOOST_EN = 1;
- BOOST_PWM.write(DUTY_CYCLE);
- stim_progress = false;
- stimTicker.attach(&stimProgress, 1);
-}
-
-void stopStimProcess() {
- if (!stim_mode) return;
-
- stimTicker.detach();
-
- stim_count = 0;
- stim_active = false;
- stim_mode = false;
- stim_progress = false;
-
- HB_CH1 = 0;
- HB_CH2 = 0;
-
- BOOST_EN = 0;
- BOOST_PWM.write(0);
-
- // DAC = 0
-}
-
+// -----------------------------------------------------------------------------
int main()
{
- SW_ONOFF.mode(PullUp);
- SW_MODE.mode(PullUp);
- SW_PLUS.mode(PullUp);
- SW_MINUS.mode(PullUp);
+ uint8_t ch_state = CH_INIT;
+ unsigned int dummy_count = 0, dummy_count_post;
- SW_ONOFF.fall(&flip_ONOFF);
- SW_MODE.fall(&flip_MODE);
- SW_PLUS.fall(&flip_PLUS);
- SW_MINUS.fall(&flip_MINUS);
+ ch1 = 0;
- HB_CH1 = 0;
- HB_CH2 = 0;
- BOOST_EN = 0;
- VEN_3V3B = 0;
-
- BOOST_PWM.period_us(100);
-
- LEDR.period_us(500);
- LEDG.period_us(500);
- LEDB.period_us(500);
-
- while(1)
- {
- if (!low_power) {
- SW_MODE.enable_irq();
- SW_PLUS.enable_irq();
- SW_MINUS.enable_irq();
-
- VEN_3V3B = 1;
-
- intensity = 0;
+ while(1) {
+ switch (ch_state) {
+ case CH_INIT:
+ ch1 = 0;
+ ch_progress = false;
+ ch_boost_done = false;
+ dummy_count = 0;
+ dummy_count_post = 0;
+ ch_state = CH_BOOST_START;
+ break;
+ case CH_BOOST_START:
+ ch_state = CH_BOOSTING;
+
+ led1 = 1; // Give visual indication at start of boost stage
+
+ case CH_BOOSTING:
+ t.start();
+ //core_util_critical_section_enter(); // critical sections affect the timer t?
+ ch1 = 1; // Boost for 100us
+ wait_us(100); // This blocks the main thread, so cannot measure during 100us boost stage
+ ch1 = 0;
+ //core_util_critical_section_enter();
+ t.stop();
+
+ dummy_count++; // measure response during 100us boost stage .. will read as 1 due to blocking wait_us
+
+ ch_state = CH_POST_BOOST;
+ chStateTimeout.attach_us(&timeoutHandler, 1000);
+ case CH_POST_BOOST:
+ dummy_count_post++; // measuring response after boost stage for 1ms
+
+ if (ch_progress) {
+ ch_progress = false;
+ ch_state = CH_WAIT_200MS;
+ chStateTimeout.attach(&timeoutHandler, 0.2f);
+ }
+ break;
+ case CH_WAIT_200MS:
+ if (ch_progress) {
+ ch_progress = false;
+ led1 = 0; // Turn off boost indication
+ ch_state = CH_WAIT_800MS;
+ chStateTimeout.attach(&timeoutHandler, 0.8f);
+ }
+ break;
+ case CH_WAIT_800MS:
+ if (ch_progress) {
+ ch_progress = false;
+ ch_state = CH_INIT;
+ pc.printf("CH_BOOSTING COUNT: %d; CH_POST_BOOST COUNT: %d; TIME TAKEN: %d\r\n", dummy_count, dummy_count_post, t.read_us()); // print measured response;
+ t.reset();
+ }
+ break;
+ }
- while (!low_power) {
- if (stim_mode && !stim_active) {
- startStimProcess();
- }
-
- if (stim_active) {
- LEDR.write(0.5f);
- LEDG.write(0.25f);
- LEDB.write(0);
-
- if (stim_progress) {
- stim_progress = false;
-
- LEDR.write(0.5f);
- LEDG.write(0);
- LEDB.write(0.5f);
-
- stimulate();
-
- if (++stim_count == 4) {
- stopStimProcess();
- }
-
- wait(0.2f);
- }
- }
- else {
- LEDR.write(0);
- LEDG.write(0.5f);
- LEDB.write(0);
- }
-
- if (flip_power) {
- flip_power = false;
- wait(0.2f);
- low_power = true;
- }
-
- __WFE();
- __SEV();
- __WFE();
- }
- }
- else {
- SW_ONOFF.disable_irq();
- SW_MODE.disable_irq();
- SW_PLUS.disable_irq();
- SW_MINUS.disable_irq();
-
- stopStimProcess();
-
- VEN_3V3B = 0;
-
- LEDR.write(0);
- LEDG.write(0);
- LEDB.write(0);
-
- wait(0.2f);
-
- SW_ONOFF.enable_irq();
-
- nrf_gpio_cfg_sense_input(15, NRF_GPIO_PIN_PULLUP, NRF_GPIO_PIN_SENSE_LOW);
- NRF_POWER->SYSTEMOFF = 1;
-
- if (flip_power) {
- flip_power = false;
- wait(0.2f);
- low_power = false;
- }
- }
-
- __WFE();
- __SEV();
- __WFE();
- }
-
- return 0;
+ }
}
diff -r 18409537564c -r 0f0c1a9a174a mbed-os.lib --- a/mbed-os.lib Sat Mar 30 06:37:35 2019 +0000 +++ b/mbed-os.lib Fri May 10 05:51:35 2019 +0000 @@ -1,1 +1,1 @@ -https://github.com/ARMmbed/mbed-os/#51d55508e8400b60af467005646c4e2164738d48 +https://github.com/ARMmbed/mbed-os/#0f959dbe4749c20416236e4fe1dac5692cbe18ab
diff -r 18409537564c -r 0f0c1a9a174a mbed_app.json
--- a/mbed_app.json Sat Mar 30 06:37:35 2019 +0000
+++ b/mbed_app.json Fri May 10 05:51:35 2019 +0000
@@ -1,13 +1,7 @@
{
"target_overrides": {
- "*": {
- "platform.stack-stats-enabled": true,
- "platform.heap-stats-enabled": true,
- "platform.cpu-stats-enabled": true,
- "platform.thread-stats-enabled": true,
- "platform.sys-stats-enabled": true
- },
"NRF52_DK": {
+ "target.uart_hwfc": 0,
"target.extra_labels_add": ["SOFTDEVICE_NONE"],
"target.extra_labels_remove": ["SOFTDEVICE_COMMON", "SOFTDEVICE_S132_FULL", "NORDIC_SOFTDEVICE", "NORDIC_CORDIO", "CORDIO", "CORDIO_LL"]
}