Posted on Leave a comment

ESP32TimerInterrupt Simple Example

Here’s a stripped down example of Khoi Hoang’s ESP32TimerInterrupt library. The library claims to run up to 16 compares (or alarms) on one, single timer. It seems to work well although I’ve only tested 3 timers thus far. I plan to use it on my Idiot Christmas Light Controller controlling triacs.

include <Arduino.h>
 /
   TimerInterruptTest.ino
   For ESP32 boards
   Written by Khoi Hoang
 Built by Khoi Hoang https://github.com/khoih-prog/ESP32TimerInterrupt
   Licensed under MIT license
 This is the most basic example using Khoi Hoang's ESP32TimerInterrupt library.  
   The library works well, but I found myself wanting an ultra basic version to understand the functionality
 */
 define TIMER_INTERRUPT_DEBUG 0
 define TIMERINTERRUPT_LOGLEVEL 0
 include "ESP32TimerInterrupt.h"
 // Change these to whatever GPIO you'd like to toggle
 define LED0 25 // GPIO 25
 define LED1 27 // GPIO 27
 define LED2 33 // GPIO 33
 // The lenght of each timer in milliseconds
 define TIMER0_INTERVAL_MS 100
 define TIMER1_INTERVAL_MS 3000
 define TIMER2_INTERVAL_MS 400
 void IRAM_ATTR TimerHandler0(void)
 {
   static bool toggle0 = false;
 //timer interrupt toggles pin LED0
   digitalWrite(LED0, toggle0);
   toggle0 = !toggle0;
 }
 void IRAM_ATTR TimerHandler1(void)
 {
   static bool toggle1 = false;
 //timer interrupt toggles LED1
   digitalWrite(LED1, toggle1);
   toggle1 = !toggle1;
 }
 void IRAM_ATTR TimerHandler2(void)
 {
   static bool toggle2 = false;
 //timer interrupt toggles LED2
   digitalWrite(LED2, toggle2);
   toggle2 = !toggle2;
 }
 // Init ESP32 timer 0,1, and 2
 ESP32Timer ITimer0(0);
 ESP32Timer ITimer1(1);
 ESP32Timer ITimer2(2);
 void setup()
 {
 pinMode(LED0, OUTPUT);
   pinMode(LED1, OUTPUT);
   pinMode(LED2, OUTPUT);
 Serial.begin(115200);
   while (!Serial)
     ;
 delay(100);
 Serial.print(F("\nStarting TimerInterruptTest on "));
   Serial.println(ARDUINO_BOARD);
 Serial.println(ESP32_TIMER_INTERRUPT_VERSION);
 Serial.print(F("CPU Frequency = "));
   Serial.print(F_CPU / 1000000);
   Serial.println(F(" MHz"));
 // Using ESP32  => 80 / 160 / 240MHz CPU clock ,
   // For 64-bit timer counter
   // For 16-bit timer prescaler up to 1024
 // Setup Timer0
   // Interval in microsecs
   if (ITimer0.attachInterruptInterval(TIMER0_INTERVAL_MS * 1000, TimerHandler0))
   {
     Serial.print(F("Starting  ITimer0 OK, millis() = "));
     Serial.println(millis());
   }
   else
     Serial.println(F("Can't set ITimer0. Select another freq. or timer"));
 // Setup Timer1
   // Interval in microsecs
   if (ITimer1.attachInterruptInterval(TIMER1_INTERVAL_MS * 1000, TimerHandler1))
   {
     Serial.print(F("Starting  ITimer1 OK, millis() = "));
     Serial.println(millis());
   }
   else
     Serial.println(F("Can't set ITimer1. Select another freq. or timer"));
 // Setup Timer2
   // Interval in microsecs
   if (ITimer2.attachInterruptInterval(TIMER2_INTERVAL_MS * 1000, TimerHandler2))
   {
     Serial.print(F("Starting  ITimer2 OK, millis() = "));
     Serial.println(millis());
   }
   else
     Serial.println(F("Can't set ITimer1. Select another freq. or timer"));
 Serial.flush();
 }
 void loop()
 {
 }

#008 – LCSC, JLCPCB Assembly, and School Python

It was a strange week. I have my first “real” job since 2003. (I’m talking full-time job.) It was a struggle to get this podcast out. I’m feeling my grip on my my reality from just 5 days ago slip away. Regardless, I was able to maintain my usual, low standards. I had plenty to talk about. I spent about a day finding a switch on LCSC. I learned a ton about the JLCPCB Assembly process, and it turns out that school may have been onto something in Python.

#007: Incredible Synth Filter, SMD MIDI Optocouplers, and Woes of Production

Pocast 007 : Incredible Synth Filter, SMD MIDI Optcouplers, and Woes of Production

Last week’s video:
LTspice Potentiometer Download and Install

— Filters
—– Scowering the web
——- found interesting schematic
——- built it up. It acted weird.
——- I simulated it in LT Spice
——–I It was still weird. It wasn’t a LPF at all, but some kind of goofy resonant peak thing.
——–Later on, I re-read the description and it said, “Fake LPF”. Sigh.
— No forum schematics? Fake news?

— Incredible video on synth design
——-DIY Synth Design Tutorial Series – 003: Analog Filter and Power Supply
——-https://www.youtube.com/watch?v=efnBC_zZduA
———- This guy knows his stuff. He gets into the real design. the.room.dis.connect

—— Introduces LM13700 transconductance amplifier
———- We all know what an RC filter is?
————– The R is little more than current control.
————– The cap is a bucket and the “current” is the flow of water to fill up that bucket.
————— What if we wanted to control R on the fly?….potentiometer
—————— What if we wanted to control a stereo 4-pole filter. We’d need an 8-gang potentiometer.
———- This led the search for a VCR (voltage controlled resistor)
—————I knew a MOSFET’s Rds does this, at least to a certain degree.
—————This would require some real chops
———- Enter the LM13700 transconductance amplifier.
—————— Essentially a VCR… voltage in controls current out.

Filter conclusion: Transconductance amplifiers allow us to control filter frequency.
———— allows creative options as CV

Back to LM13700
— About $1 in quantity
— Plenty of them on Digikey and LCSC
— A mono, four pole filter needs 2.
—- The datasheets “Application Information” is sensational.

SMD Optocoupler For MIDI TLP2361
https://calcium3000.wordpress.com/projects/teensy-midi-interface/
This guy made a super helpful blog post showing how he made his Teensy MIDI board using TLP2361 opto coupler

Posted on Leave a comment

LtSpice Potentiometer Model

It takes about 20 seconds to put a potentiometer model in LtSpice. I have no idea why it wasn’t included. Regardless….

— Download the “Pot” folder at https://github.com/brandondrury/LTspice-Libraries

— Find your C:\Users\YOUR_USERNAME\Documents\LTspiceXVII\lib\ folder
— Place pot.asy in your “sym” folder. C:\Users\YOUR_USERNAME\Documents\LTspiceXVII\lib\sym\
— Place pot.sub in your “sub” folder. C:\Users\YOUR_USERNAME\Documents\LTspiceXVII\lib\ sub\
— Click the text tool. Select “SPICE Directive” and paste in .include pot.sub.
— Restart LTspice
— Creat a new schematic. Press F2. You should see “Pot”.

The wiper is on a 0-1 scale. 1 = 100%. 0.5 = 50%.
There is a glitch that occurs if a resistor is 0 ohms in LtSpice. So, this pot actually is limited from 0.001 – 0.999 so don’t freak out if your values are off by 0.1% on extreme settings.