Stroboscopic Glasses! PWM Control special functionality questions

Status
Not open for further replies.

shadeofgreen

New member
I want to make special Stroboscopic glasses with 2 of Adafruit’s LCD Shutter Glass(https://www.adafruit.com/product/3330) and a Teensy 3.1 or 3.6. One Shutter Glass for each eye to achieve effects similar to https://www.youtube.com/watch?v=xQrsebNnQdY from https://senaptec.com/senaptecstrobe/

I want to DIY this because I want some extra features they have not implemented yet, I want to save a little cash, and I want to learn more about electronics and programming with this project.

DETAILS of desired functionality:

Left and right eye Shutter Glasses desired functionality:
-L & R can have different frequencies,
-L & R absolute phase can be changed independently if L& R have different frequencies,
-L& R relative phase can be changed if frequencies are the same

1.Frequency: I want my square wave to have a range between 0 and 360 Hz (360 at least, way higher is good too… but I do want to be able to have very slow frequencies Hz < 1).

2. Pulse Width: I want to be able to determine the width of the pulse. (I think it is commonly called changing the duty cycle). So that It could be anything between 0% and 100% of the cycle.

3.Inversion: I also want to be able to control if the pulse is pulsing high or low by being able to invert the signal.

3/4. Pulse Position / Phase: I want to control where the pulse happens curing the cycle, in effect changing it’s “absolute phase”.

5. Also I want the output square wave to go between 0V - 5V because 5V is the max recommended voltage for the Shutter Glass to make it as opaque as possible.

*See attached picture*
Teensy PWD Phasing visual-2.jpg


PROGRESS:
1. Can make L & R PWMs have different frequencies (This is an assumption based on the actual testing done with one Shutter Glass).

2. Can change pulse widths / duty cycles, but I don’t think I can control where the pulse starts during the cycle. I think I can only control the ratio of HIGH and LOW coming out of the PWM. If I make a small pulse-width / duty-cycle, it is a short HIGH pulse at the beginning of the cycle. With a high pulse-width / duty-cycle, then it is a short LOW pulse at the end of the cycle. So this is sort of a quick and easy way to do the inversion I mentioned, but it is really not what I want.

3. I haven’t tested it out yet, but I am pretty sure I can get relative opposite phases between L & R if they’re at the same frequency pretty easily. (Maybe by somehow setting the FTMs to be “complimentary”, I think the FTMs have this capability).

NOTES:

*Code tested and working so far attached at bottom*

We accidentally busted the Teensy we were using trying to make a little voltage doubling circuit so the output would be 0V-5V instead of the 0V-3.3V Teensy does. I am going to put pins on the back-up Teensy 3.1 tonight so I can get back to testing.


HELP NEEDED:

How can I achieve this absolute and relative phasing with the Teensy 3.x Libraries / Capabilities? Is it possible?

How can I separate the control of the pulse-width / duty-cycle from the inversion functionality?

What is the best way to get the signal from 0V-3.3V to 0V-5V?

What do ya’ll think?



CODE:
This is the code that I have actually tested with the hardware and had working. I can attach one of the Shutter Glass parts to pin 13 to use digital methods, or pin 4 for analog PWM.
I tried out using an IntervalTimer and then also decided to try out the FTMs and PWM pins and analogWrites with controlling Resolution and Frequency. I think I want to figure out a way to use the FTMs and PWM pins for this project for less computation needed by the CPU and more precision.
Code:
// Create an IntervalTimer object 
IntervalTimer myTimer;

float f = 10; //Hz
double microseconds_period = 1000000/f;

// The interrupt will blink the LED, and keep
// track of how many times it has blinked.
volatile unsigned long blinkCount_L = 0; // use volatile for shared variables

const int SIGNAL_PIN_1 = 13; //13 for LED

void setup() {
  // put your setup code here, to run once:
  

  analogWriteFrequency(4, 30); //(pin,Hz) 
  //1,000,000 = 1 MHz
  //100,000 = 100kHz = 0.1 MHz
  //Canges FTM1 frequency!?
  // Teensy 3.0 pin 3 also changes to 375 kHz

  analogWriteResolution(8); 
  //8 bit resolution
  //0 to 255 
  //Writing 256 forces the pin always high

  analogWrite(4,240);

  //ignoring above and doing it with digital outputs
  pinMode(SIGNAL_PIN_1, OUTPUT);

  //myTimer.begin(function, microseconds);
  //myTimer.begin(blink_L, 150000);  // blinkLED to run every 0.15 seconds: 150,000 us
  myTimer.begin(blink_L, microseconds_period);
}

int ledState = LOW;
// functions called by IntervalTimer should be short, run as quickly as
// possible, and should avoid calling other functions if possible.
void blink_L(void) {
  if (ledState == LOW) {
    ledState = HIGH;
    blinkCount_L = blinkCount_L + 1;  // increase when LED turns on
  } else {
    ledState = LOW;
  }
  digitalWrite(SIGNAL_PIN_1, ledState);
}
 
Status
Not open for further replies.
Back
Top