Last updated by at .

Monthly Archives: October 2012

Tenor Saxophone: Angin Malam

Saya mencoba bernyanyi menggunakan saxophone tenor lagu Angin Malam yang biasa dinyanyikan oleh sang lengendaris Broery Marantika.

YouTube Preview Image

 

Posted in Saxophone, Video | Tagged | Leave a comment

OpenPilot Countdown

There is a huge countdown at OpenPilot. Exciting!
Today I noticed that there is a huge countdown covering the start page at http://openpilot.org/
I also noticed that the Revo board -thread is closed for upcoming news. One can’t be certain, but t… Continue reading

Posted in CopterControl, Multicopter, OpenPilot | Comments Off

Software Serial

For users with arduino microcontroller has one serial port, such as nano arduino, uno etc., can use the digital port as an additional serial channel. I tried it into the arduino nano board, and will add an additional serial port to D10  as RX and D11 as TX. D10 (RX), D11) is a serial software controlled, unlike the RX (D0) and TX (D1) working in hardware. Required libraries that support additional serial operation, simply add the syntax:

#include<SoftwareSerial.h> 

at the beginning of the arduino program. To test the digital pin is used as an RS232 serial communication channels, required-digital USB-Serial dongle. 

Posted in Arduino, Tutorial | Tagged , , | 2 Comments

Timer 2 interrupt event: TIMER2_OVF_vect

In this post, will describe how to use an interrupt event of timer2 using nano board. If you want a process that works in the background and separated from the function loop (), you can use timer2. Timer2 can be set as a timer with overflow mode. When timer2 overflow, certain vector address to be executed. In arduino, vector address to timer2 with overflow mode is TIMER2_OVF_vect.

Initialization of timer2

First you must initialize timer2 as timer overflow mode. To initialize timer2 use the following code:

The code to initialize timer2 can be explained as follows:

  1. At line 10 aims to disable timer2, so that does not work.
  2. At line 12 aims to set timer2 to become overflow during 10ms. 
  3. At line 13 aims to clear flag interrupt of timer2. Each 10ms this flag will be set and will execute address of interrupt: TIMER2_OVF_vect
  4. At line 14 aims to enable timer2 interrupt as overflow mode.
  5. At line 15 aims to set wave generator normal of timer2
  6. AT line 16 aims to set prescaler of timer2 to 1024

How to calculate time of overflow interrupt

The equation is: 

t = (1/F) * 1024 * (255 – R) * 1000 mS

F is frequency of microcontroler in Hz
R is value of TCNT2 register

For example timer overflow will generate every 10mS (t) dan F is 16000000MHz.

10 = (1/16000000) * 1024 * (255-R) * 1000
(255 – R) = (10 * 16000000)/(1024 * 1000)
(255 – R) = 156.25
R = 255 – 156.25 =  ~98 (decimal)

Routine of timer2 overflow interrupt

If the register is set to 98, the routine of timer2 overflow interrupt will be executed every 10ms. Address of vector interrupt is TIMER2_OVF_vect.

In this routine thing to do is to set TCNT2 = 98, so the routine is executed again every 10ms. Additionally TIFR2 set to 00, TIFR2 = 00.

Next, you can add the code in this routine, such as a counter or other variables. Make the code as short as possible, try the code created only manipulate variables.

Codes above can be explained as follows:

  1. Line 21 and 22, set timer2 counter to 10ms and reset timer2 interrupt flag.
  2. Line 24 to 28, change the logic of variable flag_led as toggle every 500ms, using variable flag_500ms as counter to get again time of 500ms.
  3. Line 24, check the flag_500ms whether zero. If zero is reached, flag_led will be invert (line 26). Next on line 27 refresh flag_500ms become value of 50 as time counter of 500ms.

Setup() and Loop() functions

The code of setup() and loop() functions be explained as follows:

  1. On setup() function, line 35 configure D2 to D9 as digital output. Line 36 setup the variable of flag_500ms = 50 for 500ms counter based on 10ms. Line 37 init the timer2 as timer overflow interrupt for time of 10ms.
  2. On loop() function, line 42 and 43 set D2 to D9 with logic 0/1 based on flag_led variable.

Demo

YouTube Preview Image

Posted in Arduino, Tutorial | Tagged , , | 4 Comments