vogelchr / vserial-am2302

ATmega32u4 USB interface to a AM2302 Temperature/Humidity Sensor
0 stars 0 forks source link

Am2302 issue #1

Closed Rocky-Reddy closed 10 years ago

Rocky-Reddy commented 10 years ago

hello, I have a small doubt, In Am2302.c file in your code how does SIGNAL(TIMER1_capt_vect) works.? and where It is called.??

thankyou,

vogelchr commented 10 years ago

Hello rocky4b4,

I have a small doubt, In Am2302.c file in your code how does SIGNAL(TIMER1_capt_vect) works.? and where It is called.??

the function "SIGNAL(TIMER1_capt_vect)" is an interrupt handler. That particular signal is called when the Timer1 input capture unit has captured a timestamp.

Here's the avr-libc documentation for all things related to interrupts: http://www.nongnu.org/avr-libc/user-manual/group__avr__interrupts.html

The input capture logic for timer 1 is explained in the ATmega32U4 datasheet (AVR document 7766F–AVR–11/10, google for "ATmega32U4 datasheet") §14.5 (page 115):

/The Timer/Counter incorporates an input capture unit that can
capture external events and give them a time-stamp indicating time
of occurrence. The external signal indicating an event, or multiple
events, can be applied via the ICPn pin or alternatively, for the
Timer/Counter1 only, via the Analog Comparator unit. The time-stamps
can then be used to calculate frequency, duty-cycle, and other
features of the signal applied. Alternatively the time-stamps can be
used for creating a log of the events.//
/

Basically your timer stores its current value, when the input-capture pin changes state, and upon that event, the corresponding interrupt routing starts executing.

 Chris