정보나눔

오픈소스하드웨어 프로젝트에 대한 다양한 정보를 나누는 공간입니다.

MsTimer2에 대한 점멸 단위 시간을 milis에서 100microsec로 변환하는 방법을 알려주십시요
이수인 | 2016-12-28

1.  프로그램 중에 MsTimer2::set(100, flash); // 100milis period를 100microsec로 변화하는 방법을 알려주십시면 감사하겠습니다

2. header file 중에서 #include <avr/interrupt.h>과 <Arduino.h>을 추가하지 않아도 업로드되어 정상적으로 실행되는 이유가 무었입니까?   

상기 두가지 문제에 대한 해결을 부탁합니다.

스케치 파일

/*
 MsTimer2는 인간과 Timer2를 연결하는 작고 사용하기 쉬운 라이브러리입니다.
 timer2에서 1 msec의 해상도를 "hardcodes"하기 때문에 MsTimer2라고합니다.
 자세한 내용은 다음을 참조하십시오. http://www.arduino.cc/playground/Main/MsTimer2
*/
#include <MsTimer2.h>

// Switch on LED on and off each half second

#if ARDUINO >= 100
const int led_pin = LED_BUILTIN;    // 1.0 built in LED pin var
#else
const int led_pin = 13;            // default to pin 13
#endif


void flash()
{
  static boolean output = HIGH;
  
  digitalWrite(led_pin, output);
  output = !output;
}

void setup()
{
  pinMode(led_pin, OUTPUT);

  MsTimer2::set(100, flash); // 100ms period를 100microsec로 변화낳는 방법을 알려주십시면 감사하겠습니다요?  
  MsTimer2::start();
}

void loop()
{
}

 

1. header file

 

#ifndef MsTimer2_h
#define MsTimer2_h

#ifdef __AVR__
#include <avr/interrupt.h>
#elif defined(__arm__) && defined(TEENSYDUINO)
#include <Arduino.h>
#else
#error MsTimer2 library only works on AVR architecture
#endif

namespace MsTimer2 {
    extern unsigned long msecs;
    extern void (*func)();
    extern volatile unsigned long count;
    extern volatile char overflowing;
    extern volatile unsigned int tcnt2;
    
    void set(unsigned long ms, void (*f)());
    void start();
    void stop();
    void _overflow();
}

#endif

프로필사진

Klant 2016-12-29 13:23:17

http://forum.arduino.cc/index.php?topic=62422.0

 

위 링크를 참고하시면 아시겠지만, msTimer의 시간 단위 분해능은 millisecond 단위이기 때문에 microsecond 사용은 힘들 것 같네요 ;) 

프로필사진

이수인 2017-01-02 09:18:05

참고하겠습니다

이전글   |    2016-12-25
다음글   |    UART(RS232)통신을 적용했는데 전송 데이터를 영어에서 한글로 나타내고 싶습니다.... 2016-12-28