<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="bbPress/1.0.2" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title>LeafLabs Garden &#187; Topic: Test data received by interruption</title>
		<link>http://forums.leaflabs.com/topic.php?id=9529</link>
		<description>A place to share, learn, and grow...</description>
		<language>en-US</language>
		<pubDate>Fri, 22 Jan 2016 00:20:36 +0000</pubDate>
		<generator>http://bbpress.org/?v=1.0.2</generator>
		<textInput>
			<title><![CDATA[Search]]></title>
			<description><![CDATA[Search all topics from these forums.]]></description>
			<name>q</name>
			<link>http://forums.leaflabs.com/search.php</link>
		</textInput>
		<atom:link href="http://forums.leaflabs.com/rss.php?topic=9529" rel="self" type="application/rss+xml" />

		<item>
			<title>Bernardo769 on "Test data received by interruption"</title>
			<link>http://forums.leaflabs.com/topic.php?id=9529&amp;page=2#post-21116</link>
			<pubDate>Fri, 16 Nov 2012 15:52:27 +0000</pubDate>
			<dc:creator>Bernardo769</dc:creator>
			<guid isPermaLink="false">21116@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Hi,&#60;br /&#62;
I used a second Maple with this sketch :&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;#include &#38;lt;Servo.h&#38;gt;

#define PoloDigi4 26
Servo myservo;

void setup(){
  pinMode(BOARD_LED_PIN, OUTPUT);
    // Servo :
    myservo.attach(PoloDigi4);
}

// Move the servo to one extreme then to the other
void loop(){
  togglePin(BOARD_LED_PIN);
  for (int valServo=1000; valServo&#38;lt;2000; valServo++){
    myservo.writeMicroseconds(valServo);  // OK
    delay(1);
  }
  togglePin(BOARD_LED_PIN);
  for (int valServo=2000; valServo&#38;gt;1000; valServo--){
    myservo.writeMicroseconds(valServo);  // OK
    delay(1);
  }
}&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;With a connection between Maple1-pin20 to Maple2-pin26&#60;/p&#62;
&#60;p&#62;I still have the problem :&#60;br /&#62;
&#60;a href=&#34;http://bernard.o.perso.neuf.fr/Electronic/MAPLE/BugRC/sourceMaplePWM.jpg&#34; rel=&#34;nofollow&#34;&#62;http://bernard.o.perso.neuf.fr/Electronic/MAPLE/BugRC/sourceMaplePWM.jpg&#60;/a&#62;&#60;/p&#62;
&#60;p&#62;If there is no other solution, I'll put up a soft filter to eliminate and correct the incorrect values.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>gbulmer on "Test data received by interruption"</title>
			<link>http://forums.leaflabs.com/topic.php?id=9529&amp;page=2#post-21054</link>
			<pubDate>Wed, 14 Nov 2012 15:02:02 +0000</pubDate>
			<dc:creator>gbulmer</dc:creator>
			<guid isPermaLink="false">21054@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Bernardo769 - You can use a second Maple, but you don't &#60;em&#62;need&#60;/em&#62; a second Maple. &#60;/p&#62;
&#60;p&#62;Take a PWM output pin, and connect it back into the pin you are trying to test. The timers are pure hardware, so once the values for frequency and 'pwmWrite' ratio are set, they don't generate interrupts, or run any software.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>Bernardo769 on "Test data received by interruption"</title>
			<link>http://forums.leaflabs.com/topic.php?id=9529&amp;page=2#post-21053</link>
			<pubDate>Wed, 14 Nov 2012 13:13:52 +0000</pubDate>
			<dc:creator>Bernardo769</dc:creator>
			<guid isPermaLink="false">21053@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;My lack of experience forces me to ask the obvious questions for you.&#60;br /&#62;
I'll use a second Maple to generate a PWM signal clean.&#60;br /&#62;
I will keep you informed of the outcome.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>gbulmer on "Test data received by interruption"</title>
			<link>http://forums.leaflabs.com/topic.php?id=9529&amp;page=2#post-21043</link>
			<pubDate>Tue, 13 Nov 2012 16:14:23 +0000</pubDate>
			<dc:creator>gbulmer</dc:creator>
			<guid isPermaLink="false">21043@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Bernardo769 - what are you asking? I am not clear.&#60;/p&#62;
&#60;p&#62;A simple technique to generate consistently timed events, potentially useful to test interrupts, is to use a signal from a timer. Once set, the timer will be relatively stable (using the MCU's crystal), and consistent.&#60;/p&#62;
&#60;p&#62;A very simple approach, which needs very little software is feed a timers PWM output into a pin, and that gives a signal source which can trigger an interrupt.&#60;br /&#62;
By adjusting the duration of the timer count, you can sweep it across a range of frequencies in 1/72,000,000 increments.&#60;br /&#62;
By using two timer outputs from the same timer, you can trigger two pins, and by adjusting the PWM value for each, you can set which pin changes first and second.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>Bernardo769 on "Test data received by interruption"</title>
			<link>http://forums.leaflabs.com/topic.php?id=9529&amp;page=2#post-21041</link>
			<pubDate>Tue, 13 Nov 2012 15:26:29 +0000</pubDate>
			<dc:creator>Bernardo769</dc:creator>
			<guid isPermaLink="false">21041@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;If you have specific tests, I can do it, even if I do not control everything...
&#60;/p&#62;</description>
		</item>
		<item>
			<title>gbulmer on "Test data received by interruption"</title>
			<link>http://forums.leaflabs.com/topic.php?id=9529#post-21040</link>
			<pubDate>Tue, 13 Nov 2012 14:27:40 +0000</pubDate>
			<dc:creator>gbulmer</dc:creator>
			<guid isPermaLink="false">21040@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;ala42 - I think it is possible for SysTick to fire after the calculation of millis in &#60;code&#62;while (ms != millis());&#60;/code&#62;, but before &#60;code&#62;if(systick_check_underflow())&#60;/code&#62; gets to check the value, so it is just possible that this will also give the wrong value very occasionally.&#60;/p&#62;
&#60;p&#62;AFAIK, SysTick priority can be changed, though I have never tried to do that. &#60;/p&#62;
&#60;p&#62;So it &#60;em&#62;might&#60;/em&#62; be simpler to raise the SysTick priority above the interrupt service routine; simpler in the sense that micros() and millis() would work without extra checking.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>Bernardo769 on "Test data received by interruption"</title>
			<link>http://forums.leaflabs.com/topic.php?id=9529#post-21012</link>
			<pubDate>Mon, 12 Nov 2012 13:26:15 +0000</pubDate>
			<dc:creator>Bernardo769</dc:creator>
			<guid isPermaLink="false">21012@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Despite all the proposed changes, I still worry.&#60;/p&#62;
&#60;p&#62;In summary of the changes:&#60;/p&#62;
&#60;p&#62;Sketch :&#60;br /&#62;
&#60;pre&#62;&#60;code&#62;#include &#38;quot;voieRC.h&#38;quot;
#include &#38;lt;Servo.h&#38;gt;
#include &#38;quot;nvic.h&#38;quot;

#define Serial SerialUSB

#define pinVoieGAZ 20
voieRC voieGAZ(pinVoieGAZ);

#define PoloDigi4 26
Servo myservo;

void setup() {
  attachInterrupt(pinVoieGAZ, interruptRC_GAZ, CHANGE);
  // Servo :
  myservo.attach(PoloDigi4);
}

void loop() {
  //SerialUSB.println(voieGAZ.valeur());
  myservo.writeMicroseconds(constrain(voieGAZ.valeur(), SERVO_DEFAULT_MIN_PW, SERVO_DEFAULT_MAX_PW));  // OK
  //delay(50);
}

void interruptRC_GAZ(void) {
  voieGAZ.etat();
}

void voieRC::etat() {
  //noInterrupts();
  if (digitalRead(this-&#38;gt;pinRC) == HIGH) {  // Front montant
    timeUP = micros();
    timeDOWN = timeUP;
  }
  else {  // Front descendant
    timeDOWN = micros();
    lastValidValue = timeDOWN - timeUP;
  }
  //interrupts();
}&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;wirish_time.h :&#60;br /&#62;
&#60;pre&#62;&#60;code&#62;static inline uint32 micros(void) {
    uint32 ms;
    uint32 cycle_cnt;
    uint32 res;

    do {
        ms = millis();
        cycle_cnt = systick_get_count();
    } while (ms != millis());

    if(systick_check_underflow()) {
    	ms++;
    	cycle_cnt = systick_get_count();
    }

    /* SYSTICK_RELOAD_VAL is 1 less than the number of cycles it
       actually takes to complete a SysTick reload */
    res = (ms * US_PER_MS) +
        (SYSTICK_RELOAD_VAL + 1 - cycle_cnt) / CYCLES_PER_MICROSECOND;

    return res;
}&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;All ideas are property came...
&#60;/p&#62;</description>
		</item>
		<item>
			<title>ala42 on "Test data received by interruption"</title>
			<link>http://forums.leaflabs.com/topic.php?id=9529#post-21001</link>
			<pubDate>Mon, 12 Nov 2012 06:15:49 +0000</pubDate>
			<dc:creator>ala42</dc:creator>
			<guid isPermaLink="false">21001@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;The systick IRQ has a low prio, lower that your IRQ handler, so the milli seconds counter is not updated, when the overflow occurs in your IRQ handler.&#60;br /&#62;
Add #include &#34;nvic.h&#34; and use this micros function:&#60;br /&#62;
&#60;pre&#62;&#60;code&#62;static inline uint32 micros(void) {
    uint32 ms;
    uint32 cycle_cnt;
    uint32 res;

    do {
        ms = millis();
        cycle_cnt = systick_get_count();
    } while (ms != millis());

    if(systick_check_underflow()) {
    	ms++;
    	cycle_cnt = systick_get_count();
    }

    /* SYSTICK_RELOAD_VAL is 1 less than the number of cycles it
       actually takes to complete a SysTick reload */
    res = (ms * US_PER_MS) +
        (SYSTICK_RELOAD_VAL + 1 - cycle_cnt) / CYCLES_PER_MICROSECOND;

    return res;
}&#60;/code&#62;&#60;/pre&#62;</description>
		</item>
		<item>
			<title>Bernardo769 on "Test data received by interruption"</title>
			<link>http://forums.leaflabs.com/topic.php?id=9529#post-20985</link>
			<pubDate>Mon, 12 Nov 2012 00:37:43 +0000</pubDate>
			<dc:creator>Bernardo769</dc:creator>
			<guid isPermaLink="false">20985@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;good idea.&#60;br /&#62;
I renamed the file wirish_time.h in wirish_time.h.new&#60;br /&#62;
to compile, I get the message :&#60;br /&#62;
fatal error: wirish_time.h: No such file or directory&#60;br /&#62;
The change is well used.&#60;br /&#62;
&#60;pre&#62;&#60;code&#62;/**
 * Returns time (in microseconds) since the beginning of program
 * execution.  On overflow, restarts at 0.
 * @see millis()
 */
static inline uint32 micros(void) {
    uint32 ms;
    uint32 cycle_cnt;
    uint32 res;

    do {
        ms = millis();
        cycle_cnt = systick_get_count();
    } while (ms != millis());

    /* SYSTICK_RELOAD_VAL is 1 less than the number of cycles it
       actually takes to complete a SysTick reload */
    res = (ms * US_PER_MS) +
        (SYSTICK_RELOAD_VAL + 1 - cycle_cnt) / CYCLES_PER_MICROSECOND;

    return res;
}&#60;/code&#62;&#60;/pre&#62;</description>
		</item>
		<item>
			<title>gbulmer on "Test data received by interruption"</title>
			<link>http://forums.leaflabs.com/topic.php?id=9529#post-20977</link>
			<pubDate>Sun, 11 Nov 2012 17:04:41 +0000</pubDate>
			<dc:creator>gbulmer</dc:creator>
			<guid isPermaLink="false">20977@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Bernardo769 - Good question. How about change the name of the file from wirish_time.h to xxx..xxx and see if your program compiles?
&#60;/p&#62;</description>
		</item>
		<item>
			<title>Bernardo769 on "Test data received by interruption"</title>
			<link>http://forums.leaflabs.com/topic.php?id=9529#post-20976</link>
			<pubDate>Sun, 11 Nov 2012 15:47:12 +0000</pubDate>
			<dc:creator>Bernardo769</dc:creator>
			<guid isPermaLink="false">20976@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;I still have the problem&#60;br /&#62;
I found the file wirish_time.h in the directory C:\Program Files\maple-ide-0.0.12-windowsxp32\hardware\leaflabs\cores\maple&#60;br /&#62;
When I look in the directory where the compilation is C:\Users\Olivier\AppData\Local\Temp\build7029581827160573567.tmp, how to verify that the change is taken into account
&#60;/p&#62;</description>
		</item>
		<item>
			<title>gbulmer on "Test data received by interruption"</title>
			<link>http://forums.leaflabs.com/topic.php?id=9529#post-20973</link>
			<pubDate>Sun, 11 Nov 2012 14:00:06 +0000</pubDate>
			<dc:creator>gbulmer</dc:creator>
			<guid isPermaLink="false">20973@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Bernardo769 - can you find the file wirish_time.h?&#60;/p&#62;
&#60;p&#62;On my Mac, the path is MapleIDE.app/Contents/Resources/Java/hardware/leaflabs/cores/maple/&#60;br /&#62;
so it is likely something similar on other platforms.&#60;/p&#62;
&#60;p&#62;Copy wirish_time.h to wirish_time.h.old (just in case you make a mistake)&#60;/p&#62;
&#60;p&#62;Edit the file wirish_time.h, and replace&#60;br /&#62;
&#60;pre&#62;&#60;code&#62;do {
        cycle_cnt = systick_get_count();
        ms = millis();
    } while (ms != millis());&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;with&#60;br /&#62;
&#60;pre&#62;&#60;code&#62;do {
        ms = millis();
        cycle_cnt = systick_get_count();
    } while (ms != millis());&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;Unfortunately, the whole directory structure has changed, so it might be awkward to navigate.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>Bernardo769 on "Test data received by interruption"</title>
			<link>http://forums.leaflabs.com/topic.php?id=9529#post-20971</link>
			<pubDate>Sun, 11 Nov 2012 13:21:16 +0000</pubDate>
			<dc:creator>Bernardo769</dc:creator>
			<guid isPermaLink="false">20971@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Thank you for the information.&#60;br /&#62;
I downloaded the file libmaple-master.zip&#60;br /&#62;
I'm not used to these manipulations.&#60;br /&#62;
How to install its contents. I would not do anything stupid.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>gbulmer on "Test data received by interruption"</title>
			<link>http://forums.leaflabs.com/topic.php?id=9529#post-20970</link>
			<pubDate>Sun, 11 Nov 2012 12:49:39 +0000</pubDate>
			<dc:creator>gbulmer</dc:creator>
			<guid isPermaLink="false">20970@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;bubulindo - that version of micros() contains a bug.&#60;br /&#62;
See &#60;a href=&#34;http://forums.leaflabs.com/topic.php?id=1098&#34; rel=&#34;nofollow&#34;&#62;http://forums.leaflabs.com/topic.php?id=1098&#60;/a&#62;&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;do {
        cycle_cnt = systick_get_count();
        ms = millis();
    } while (ms != millis());&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;should be&#60;br /&#62;
&#60;pre&#62;&#60;code&#62;do {
        ms = millis();
        cycle_cnt = systick_get_count();
    } while (ms != millis());&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;Sadly LeafLabs haven't updated the IDE download in the last year, so you need to patch it yourself, or go to github &#60;a href=&#34;https://github.com/leaflabs/libmaple&#34; rel=&#34;nofollow&#34;&#62;https://github.com/leaflabs/libmaple&#60;/a&#62;&#60;/p&#62;
&#60;p&#62;That bug is enough to cause the value returned by micros() to jump backwards by almost 1000 microseconds, which might explain the results.&#60;/p&#62;
&#60;p&#62;I don't think it is accurate to say &#60;/p&#62;
&#60;blockquote&#62;&#60;p&#62;Because the systick timer doesn't count microseconds, this is, as far as I can see something like millis() * 1000.
&#60;/p&#62;&#60;/blockquote&#62;
&#60;p&#62;systick counts at 72MHz, and counts down from 71999, i.e. 1 milisecond. &#60;/p&#62;
&#60;p&#62;&#60;code&#62;(ms * US_PER_MS)&#60;/code&#62; gives the number of complete milliseconds, measured in microseconds, the timer has been running.&#60;br /&#62;
&#60;code&#62;(SYSTICK_RELOAD_VAL + 1 - cycle_cnt)&#60;/code&#62; gives the number of clock cycles (72MHz) into the current millisecond&#60;br /&#62;
&#60;code&#62;(SYSTICK_RELOAD_VAL + 1 - cycle_cnt) / CYCLES_PER_MICROSECOND&#60;/code&#62; gives the number of microseconds into the current millisecond.&#60;/p&#62;
&#60;p&#62;So the calculation is yielding a microsecond resolution timer, but with a range much bigger than 1 millisecond.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>Bernardo769 on "Test data received by interruption"</title>
			<link>http://forums.leaflabs.com/topic.php?id=9529#post-20969</link>
			<pubDate>Sun, 11 Nov 2012 11:54:57 +0000</pubDate>
			<dc:creator>Bernardo769</dc:creator>
			<guid isPermaLink="false">20969@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;I have a handheld oscilloscope that gives me a correct signal to the output of the servo tester. The servo connected to the servo tester responds correctly.&#60;/p&#62;
&#60;p&#62;The output signal of servo tester is like this:&#60;br /&#62;
&#60;a href=&#34;http://robotpic.free.fr/tl_files/willy/images/servotime.gif&#34; rel=&#34;nofollow&#34;&#62;http://robotpic.free.fr/tl_files/willy/images/servotime.gif&#60;/a&#62;
&#60;/p&#62;</description>
		</item>

	</channel>
</rss>
