0

My first question here and please excuse my English. I am playing with Nordic nrf51 Timer module (using a BBC microbit v1.5). I am using Timer1 to flash a LED. I stored a value to the capture register CC[1] which, according to the reference manual, will generate a event compare[1] when the Timer counter register reaches that value. The compare[1] has an offset address and whenever the compare[1] turns to 1 I toggle the LED and have to manual set compare[1] to 0 + clear the timer counter to count from 0 again. The pseudo code is something like this:

Timer_source=timer1;
timer_bitmode is 16 bit
Prescaler=9 => 16MHz/2^9= 31250 ticks per second
Write 31250 to CC[1] ( 1 second) => compare[1] event will be generated when timer reaches CC[1]'s value
set LED_pin as output;
Start timer;
while(1){
check compare[1] (timer address + offset) if it equals 1 => toggle LED, set compare[1] to 0 and restart the timer
}

It works as expected but I would like to make sure I understand it: the compare events each of them is it a register or just 1 bit of a register which turns 1 when generated?

Kaden
  • 1

1 Answers1

0

Each of the compare events has its own 32-bit register, which can have a value of 0 or 1.

That is how events are implemented on an NRF51 MCU in general. Note that NordicSemi has nice definitions for the Timer peripherial registers (and all others) in their C headers.

Turbo J
  • 9,969
  • 1
  • 20
  • 28
  • I am trying to not to use any libraries for the purpose of learning. Just read/write to the registers. Thanks for your answer. If I understand it correctly each event has its own register and a flag bit in INTEN register which turn 1 when the event is generated ? – Kaden Jan 27 '21 at 21:39
  • A bad mistake. Not using the headers makes your code unreadable. And no, INTEN is the gatekeeper between the Event and the NVIC. Sometimes you don't want specific events to generate the peripherial interrupt. – Turbo J Jan 27 '21 at 21:48
  • I actually create the header file myself (a file of #define) and create functions just for the purpose of getting used to how it operates at register level. My header files and functions are surely messy and poorly written . I am inexperienced and will eventually use the existing libraries – Kaden Jan 27 '21 at 21:55
  • so the INTEN register is for enable and disable interrupt. when the timer reaches CC[1]'s value the INTEN register remains the same and the compare[1] resistor changes its values ? – Kaden Jan 27 '21 at 22:24