I am working on a project that involves rotating a gear-motor while also gathering light sensor information. It is very important to the success of the project that the angle rotated by the gear-motor is controlled as exactly as possible. The gear-motor is driven by a PWM signal which passes through a motor controller before reaching the actual motor. The motor also outputs encoder informations which is received by the Intel Edison board on gpio pins 3 and 5 and trigger an interrupt routine for counting the gear rotations.
The light sensor output is received by the Intel Edison Board via ADC pin A02.
I am programming the board using the Eclipse IDE and using C++ code. Tthe board is connected to the Arduino Expansion Kit is powered by the AC wall charger (not the USB port). The PWM, Interrupt and ADC functionalities are carried out by the MRAA libraries.
Rotating the motor only (not capturing light sensor data) I am able to get the motor to rotate to 360 degrees (+/- 10 deg). I do this by rotating it 6 degrees in a for loop which iterates 60 times. However when I include the light sensing function within this loop the motor rotates at least 30-50 degrees beyond the desired 360 degrees. In addition when adding the ADC function in the loop the audible noise the motor makes when rotating is slightly different from the noise it makes when I do not include the light sensing function. Measuring the PWM signal through an oscilloscope before it is passed to the motor controller shows that the signal gets interrupted when ADC functionality is used in the loop, signal is not interrupted when I am only rotating the motor.
I am suspecting that the PWM (or Interrupt) and ADC functionalities use the same resources , e.g. they both use TIMER1.
If so, would it be possible to specify that the functionality use a different resource? For example, set PWM to use TIMER2 and ADC to use TIMER1. If not would there be any other suggestions/solutions to this issue. I have tried altering the making the rotating angle smaller (for example rotate 4.5 degrees 60 times), on some runs this works and other runs it does not work. It would be preferred to have an approach with more consistency.
Any Help would be appreciated.