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);
}
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);
}