Monday, 11 January 2016

Droidbot #3 - Controlling the robot direction via a light source

The direction of the robot will be given by a light source. It will try to follow the light source.
To achieve this there are two photo resistors on each side of the robot.
Both of them are connected in a Wheatstone bridge and the output of the bridge is connected to an operational amplifier.
On the software side, we have to initialise the GPIO input pins and configure the interrupts on these pins.

A few words on interrupts:

  • Interrupts are signals to the processor, to stop the execution of the current code / context and execute some different code in a different context.
  • They can be generated by various devices, events, processes
  • Ex. rising / falling edge on a digital input pin, timer reset, analog input reaches a certain value, etc.
  • The part of the SW that defines what actions are to be taken when the interrupt occurs, is called ISR (Interrupt Service Routine).
  • For more details on interrupts check the next articles ( polling vs interrupts, wikipedia)
In our case, there will be a high level triggered interrupt on GPIO pin PF0 and PF4.

The function to initialise the GPIO pins is: GPIO_Light_sensor_init(), see file on Git Hub here.
The priority of this interrupt is configured to be 2 (0 being the highest and 7 being the lowest priority).

The function for the ISR is: GPIO_PortF_Handler(), see file on Git Hub here.
The name of this function must be predefined in the start up code, see file on Git Hub here.
It is recommended that as early as possible in the ISR to acknowledge the interrupt so that it will not self trigger again.
This was done with the GPIOIntClear API.
Also it's recommended not to have delays in the ISR, since we could loose the real time characteristic of our system.

Again, if something is not clear, feel free to comment. I will add more details to the article.

No comments:

Post a Comment