1

I am trying to understand the use of the interrupt for LDRBS in this specific pseudocode. Our task is to measure the temperature using a temp sensor.

Here is the pseudocode steps:

Initialization

1) Don’t forget the PMC
2) Select Timer_Clock1 as TCCLK
3) Enable counter and make a sw_reset in TC0_CCR0
4) Load counter to A when TIOA falling in (TC0_CMR0)
5) Load counter to B when TIOA rising in (TC0_CMR0)
6) Enable the pin
7) Create init puls
8) Enable the interrupt (NVIC) with the inline declared function

Starting the measurement

1) Create a startpuls with a Delay(25); and make a sw_reset in TC0_CCR0
2) Clear old interrupt by read statusreg
3) Enable interrupt for LDRBS

Interrupt Handler

1) Disable interrupt LDRBS
2) Set a global flag.

The steps that I don't really understand is nr 8 in the initialization and nr 3 in the measurement function. I know for step 3 I am supposed to use

*AT91C_TC0_IER = (0x1 << 6); // or (AT91C_TC_LDRBS) instead of (0x1 << 6)

But I don't understand why this step is necessary, I want to know what function the interrupt for LDRBS has in TC0

Maso
  • 35
  • 5
  • Step 8) MPU interrupts are generally disabled by default, to give the programmer the opportunity to fully prepare for them. The control bit also allows the programmer to suspend the interrupts without having to reconfigure. Step 3) xxIER is also an abbreviation for Interrupt Enable Register. There are different levels of enabling, beginning with the device itself, thru to a global enabler. – Weather Vane Jan 18 '21 at 15:27
  • @WeatherVane For the step 8 we are told to enable NVIC, I have used the following `NVIC_ClearPendingIRQ(TC0_IRQn);` & `NVIC_SetPriority(TC0_IRQn, 1);` & `NVIC_EnableIRQ(TC0_IRQn);` – Maso Jan 18 '21 at 15:33
  • @WeatherVane Also about step 3 in the measurement, I have used `*AT91C_TC0_IER = (0x1 << 6);` But I don't understand the use of this interrupt. What is it exactly doing? Why are we enabling the interrupt for LDRBS? – Maso Jan 18 '21 at 15:36
  • a) the device might have triggered an interrupt already, which you don't want to service so you clear it. b) Interrupts for different reasons can be assigned a priority, for example a low priority handler can itself be interrupted by one of higher priority. c) Now you can enable the interrupt. – Weather Vane Jan 18 '21 at 15:38
  • Before you enable the interrupt you must have an interrupt handler in place, otherwise the code will crash. Are you asking what an "interrupt" is? From the look of your code fragments, it seems that `AT91C_TC_LDRBS` is a definition for `(1 << 6)` or `64`. – Weather Vane Jan 18 '21 at 15:40
  • @WeatherVane Thanks, now I have an explanation for the NVIC. I didn't know the reason we are supposed to use it. What about the IER and bit LDRBS in TC0? – Maso Jan 18 '21 at 15:41
  • I briefly know what an interrupt is, but I don't know why we are using it in a measurement function. Especially with that bit LDRBS and TC0 (Timer/Counter) – Maso Jan 18 '21 at 15:42
  • I don't know what your project it, but it's possible that a timer is used to take regular temperature measurements. – Weather Vane Jan 18 '21 at 15:44
  • Most likely, we are supposed to print the current temperature in a display. I still don't fully understand the use of bit LDRBS in the IER though. – Maso Jan 18 '21 at 15:47
  • 1
    I recommend a thorough study of the data sheet. – Weather Vane Jan 18 '21 at 15:47

0 Answers0