Arduino PWM signal acquisition dubt

Thread Starter

Lucky-Luka

Joined Mar 28, 2019
79
I'm doing a little project in order to learn to use Arduino.
In the attached image it's shown the circuit.
3 phototransistors with 3 colored filters let a RGB LED shine accordingly to che color of the light that hit the three sensors.
I have connected my probes to the pins 11 (RED), 10 (BLUE) and 9 (GREEN).
Those are the 3 traces displayed on the oscilloscope screen. I change light conditions sequentially (RED light then GREEN light then BLUE light) and I can see that the duty cycle of the 3 signals (RED, GREEN, BLUE) change accordingly.
The red trace (PIN 11) is the one the trigger of the scope is referred to.
Its rising edge is fixed on the screen while its falling edge moves accordingly to the power supplied by the probed PIN.
When the power delivered to the PIN 10 and 9 changes looking at the GREEN and BLUE traces I notice that not only the corresponding falling edge move on the screen but even the rising edges move.
In another moment I have set the trigger for the GREEN trace: in this case only the GREE trace rising edge is fixed.
I have even set the trigger for the BLUE trace and I have noticed that only the BLUE trace rising edge is fixed.
Can sonmeone tell me what's going on?
I was expecting to see all the three rising edges traces in fixed positions on the screen.
I have to say that I'm still learning to use the scope so maybe I haven't understood something related to its settings.
Cheers
Video of the traces on the scope
 

Attachments

ericgibbs

Joined Jan 29, 2010
9,535
hi LL,
Please post your Arduino sketch for this project, so that we can check the program.
E
You will have to change the .ico extension to .txt in order to upload the sketch.
 

Thread Starter

Lucky-Luka

Joined Mar 28, 2019
79
Hi Eric
In another forum I've been told that the reason is that Pins 9 (GREEN trace) & 10 (BLUE trace) belong to Timer-1, while pin 11 (RED trace) belongs to Timer-2. Those two timers are not synchronized, so phase offset could be anything.
I've also been told that Timer 2 is 16 bits while Timer 1 is 8 bits...
Do you think that these explanations can explain the behaviour seen on the oscilloscope screen?

In the attached pic it's shown what happens when the blue signal is triggered and I use blue light.
The duty cycle of the blue trace increases while both the green and red traces just shift to the right.
If pin 9 (GREEN) and pin 10 (BLUE) refer to the same timer shouldn't those traces have the same position for the rising edges?
Cheers

C-like:
const int greenLEDPin=9;
const int blueLEDPin=10;
const int redLEDPin=11;

const int redSensorPin=A0;
const int greenSensorPin=A1;
const int blueSensorPin=A2;

int redValue=0;
int greenValue=0;
int blueValue=0;

int redSensorValue=0;
int greenSensorValue=0;
int blueSensorValue=0;

void setup() {
  Serial.begin(9600);

  pinMode(greenLEDPin,OUTPUT);
  pinMode(blueLEDPin,OUTPUT);
  pinMode(redLEDPin,OUTPUT);
}

void loop() {
  redSensorValue=analogRead(redSensorPin);
  delay(5);
  greenSensorValue=analogRead(greenSensorPin);
  delay(5);
  blueSensorValue=analogRead(blueSensorPin);

  Serial.print("Raw sensor values \t red: ");
  Serial.print(redSensorValue);
  Serial.print("\t   green: ");
  Serial.print(greenSensorValue);
  Serial.print("\t   blue: ");
  Serial.println(blueSensorValue);

  // Signal values (after ADC conversion: 0-1023) converted to PWM values (0-255)
  redValue=redSensorValue/4;
  greenValue=greenSensorValue/4;
  blueValue=blueSensorValue/4;

  Serial.print("Mapped sensor values \t red: ");
  Serial.print(redValue);
  Serial.print("\t   green: ");
  Serial.print(greenValue);
  Serial.print("\t   blue: ");
  Serial.println(blueValue);

  analogWrite(redLEDPin,redValue);
  analogWrite(greenLEDPin,greenValue);
  analogWrite(blueLEDPin,blueValue);
}
 

Attachments

Last edited:

ericgibbs

Joined Jan 29, 2010
9,535
Hi,
As you have noted Tmr1 and Tmr2 is used on those Pins, is the Scope jitter causing a problem, also is the Dimming action working OK on the LED's?
E
 

Thread Starter

Lucky-Luka

Joined Mar 28, 2019
79
I attach the setup of the circuit.
The probes are directly connected to the pins. The RGB LED is disconnected. The phototransistors have colored filters.
When the RGB LED is connected it acts more or less accordingly to what it's expected. I say more or less because I think the green filter isn't doing its job very well.
 

Attachments

ericgibbs

Joined Jan 29, 2010
9,535
hi,
I first thought you were using Rd, Gn & Bl LED's , not external filters.
I guess you know that the human eye can detect more shades of Green than any other colour .?

As the RGB LED works OK, try some different Green filter material.
E
 

Thread Starter

Lucky-Luka

Joined Mar 28, 2019
79
I'm using the material in the Arduino starter kit :)
Any final thought about those offsets on the screen?
Any final speculations?
Cheers
 
Top