Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ Programming ➜ General ➜ In the setting of the timer counter interrupt is not included.

In the setting of the timer counter interrupt is not included.

It is now over 60 days since the last post. This thread is closed.     Refresh page


Posted by Dundich   Russia  (1 post)  Bio
Date Thu 25 Sep 2014 03:35 AM (UTC)
Message
Prompt please, what settings timer-counter in my program is not so. Settings sketched, maximum identical, with musical examples Arduino, but on-board Arduino Due not included interruption. In the program reads the input pulse duration for any differential input pulse. Initially, the program was written for 328 atmega, she earned, but for my purposes the chip is rather weak.

volatile static int32_t counter1; /* Переменная - текущее показание счетчика 1 */

// Объявляем таймер-счетчик 0 и его канал 1
#define WORK_TIMER TC0
#define INPUT_CHNL 1
#define INPUT_IRQ TC1_IRQn

static Tc *chTC = WORK_TIMER;
static uint32_t chNo = INPUT_CHNL;
static uint32_t in_pin; /* Задаем A7 пин ардуино порт PA2 in_pin - 85 вывод */

// Настраиваем 1 канал: предделитель тактовой частоты 32, при изменении уровня входного импульса запись счетчика в регистр А
void set_timer1 (uint32_t ulPin) {
pmc_set_writeprotect(false);
pmc_enable_periph_clk((uint32_t)INPUT_IRQ);
TC_Configure(chTC, chNo,
TC_CMR_TCCLKS_TIMER_CLOCK3 |
TC_CMR_LDRA_EDGE);
chTC->TC_CHANNEL[chNo].TC_IER=TC_IER_LDRAS;
chTC->TC_CHANNEL[chNo].TC_IDR=~TC_IER_LDRAS;
NVIC_EnableIRQ(INPUT_IRQ);
in_pin = ulPin;
// Выставили A7 пин ардуино порт PA2 на ввод
pinMode (in_pin, INPUT);
}

void setup() {
// put your setup code here, to run once:
counter1 = 0;
Serial.begin(9600);
set_timer1 (A7);
}

void loop() {
// put your main code here, to run repeatedly:
if (counter1 != 0) {
Serial.println(counter1);
counter1 = 0;
}
}

void TC1_Handler (void) {
TC_GetStatus(TC0, 1);
TC_Stop(chTC, chNo);
counter1 = TC0->TC_CHANNEL[1].TC_RA;
TC_Start(chTC, chNo);
}
Top

Posted by Nick Gammon   Australia  (23,173 posts)  Bio   Forum Administrator
Date Reply #1 on Thu 25 Sep 2014 04:58 AM (UTC)
Message
Template:Arduino Please post Arduino-related questions to the Arduino Forum or to StackExchange: Arduino. This saves splitting questions and answers between this forum and the Arduino ones.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


11,093 views.

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.