Gas station without pumps

2017 November 8

Starting to port the Events and Services Framework to Teensy boards

Filed under: Uncategorized — gasstationwithoutpumps @ 23:23
Tags: , , ,

Because I want to work at home with boards that I own, I need to port the Events and Services framework used in the Mechatronics class to the Teensy LC or Teensy 3.1 board.  The first thing to do is to identify what resources are used by the Teensyduino framework, and so inaccessible to me (except through their API).

The ES framework itself has only one interrupt routine, in ES_Timers.c, which runs on a millisecond tick, updating FreeRunningTimer and checking to see whether any of the ES_Timers have just timed out. While I would have loved to do this with the SysTick timer on the Teensy boards, Teensyduino uses that its own millisecond timer (accessible through millis()).  So I’ll probably have to use the IntervalTimer interface, which will use up one of the PIT (programmable interrupt timer resources).

Because I’ll be doing hardware pwm on selected pins, not software pwm, I don’t need to port the pwm code from the Uno32 library.  I will need timer resources for hardware pwm, which means using pins that have pwm support.  Different pins use different timers for the pwm, and the table at provides the mapping:

Teensy 3.2
Teensy 3.1
FTM0 5, 6, 9, 10, 20, 21, 22, 23 488.28 Hz
FTM1 3, 4 488.28 Hz
FTM2 25, 32 488.28 Hz
Teensy LC FTM0 6, 9, 10, 20, 22, 23 488.28 Hz
FTM1 16, 17 488.28 Hz
FTM2 3, 4 488.28 Hz

(They provide the mapping for other Teensy boards also, but I will only use LC and 3.1/3.2 boards on this project.) If I just use two PWM channels, then pins 3 and 4 would be a good choice on either chip, as few other uses conflict with those pins and they share a timer.  If I need more than 2 PWM channels, then pins 6, 9, 10, 20, 22, and 23 share FTM0 on both chips. Three of those channels are also A-to-D channels and pin 20 is SCK1 (the second SPI interface clock).  I’m planning to use pints 11, 12, and 13 for the SPI interface, plus one other digital pin for the chip select, so the conflicts on the PWM pins are probably irrelevant.

I don’t like the default PWM frequency of 488.28 Hz, though, and so will be changing the PWM resolution and frequency to get a PWM frequency above the audible range (the MAX14870 H-bridges had no trouble handling up to 50kHz).  Using an 10-bit resolution with a clock speed of 48MHz (Teensy LC) would give me a PWM frequency of 46875Hz and  with a clock speed of 72MHz (Teensy 3.1) 35156.25Hz (the code does some prescaling).  These look like good frequencies to request.

The code provided for the Uno supports RC servos with another timer.  In the Teensyduino library there are two different servo implementations: Servo and PWMServo.  PWMServo uses the same PWM hardware that the pwm library uses, but at a 50Hz PWM frequency.  If I use that library, it will be important to cluster the servo pins on to one of the FTM timers and the pwm pins onto a different timer.  The Servo library uses the LPTM timer on the Teensy LC and the PDB timer on the Teensy 3.1/3.2, which does not conflict with other uses, but the servo timing is subject to glitching, especially if interrupts are ever disabled in the code.

The Uno32 board is set up to read analog-to-digital values continuously so that reading the data can be a non-blocking operation that just grabs the latest value without waiting for a new conversion.  For my first version of the port, I’ll just use analogRead to read pins, but if that turns out to be too slow (which it might), I’ll change to using the analog reading used by PteroDAQ. One oddity of the ES framework is that the battery-check code is built into the analog-to-digital conversion code, and the processor put to sleep if the battery is low.  I suppose this was done so that filtering of the battery voltage could be done in the interrupt routine that samples all the ADC channels.  It seems like a worthwhile thing to shut everything down if the battery gets too low, so I might decide  to do something like theADC library.  The Teensy boards don’t have an interface for cycling through the channels the way the Uno32 appears to, so I would probably have to set up a rather different interface for this.  This looks like the biggest difficulty in porting the framework—it might be better to set up a battery monitor that is not embedded so deeply in the code, perhaps having a battery-check event checker that is automatically polled.

The provided timers.c package gives access to another set of millisecond timers, which can be polled.  This library does not seem very useful—if I want to know the time, I can call millis() and if I want to poll whether enough time has elapsed, I can compare millis() to a computed stop time.  It does not seem worthwhile to use up another timer just for millisecond resolution.

I’m not planning to use a stepper motor, so I won’t port the Stepper routines (which we had to modify as a homework exercise).  If I were to port these routines, I’d probably use up another IntervalTimer (which exhausts them for the Teensy LC).

The serial.c code uses a UART interrupt to send or receive over the USB port, but the Teensyduino enviroment includes Serial, so all I would need to do is to

#define printf Serial.printf

and there is no need to port serial.

So far, it looks like the partial port that I’m planning (porting the ES framework but not the peripherals) looks very straightforward, other than the battery voltage monitor.  I might skip that in the first port, and add it back in later.


Bathroom timer knob

Filed under: Uncategorized — gasstationwithoutpumps @ 10:26
Tags: , , , ,

On Saturday, as a break from the mechatronics midterm, I rode my bike over to Gary’s Plastics (105 Bronson, opposite the Pacific Edge climbing gym) to get some acrylic sheet for cutting out electrode holders for my applied electronics course.  It took me a while to find the place, because 105 Bronson is mainly a metal-working place.  Gary’s Plastics has only a tiny sign on the side of the building, and they are at the back of a junk-strewn parking lot.

I bought the 1/4″ acrylic sheet I needed at a much lower price than San Lorenzo Lumber, which had only 1/10″ sheet, but it was clear that they did not stock a lot of stuff—if you want something specific, you probably have to order it in advance or go over the hill to TAP plastics.

While I was there, I picked up a scrap of white HDPE for another project—fixing the knob on the timer for the fan in my bathroom.  The knob for the timer broke about a year ago, and my first thought would be that it would be a trivial fix, as I had several knobs available that I had bought for various projects.  Unfortunately, none of them fit!  The standard knobs are all for 6mm shafts, and the timer had a 4.77mm shaft.

The bare shaft, which is too skinny for standard knobs, which expect a 6mm shaft.

For a while we used pliers to turn the timer on, but this was inconvenient and ugly, so I kept looking for a different solution. After a while, I found a part that was designed for a 5mm shaft, though it wasn’t intended as a knob—it is an aluminum coupler base for the Eggbot.

The aluminum coupler base from the Eggbot—looks ok but rather hard to turn with wet hands.

We used the Eggbot coupler for quite a while, but we all got irritated by the difficulty in turning it. Eventually, my son noticed that the set screw for the coupler was a standard 10-32 screw thread, and we stuck in the only 10-32 screw I happened to have on hand (I have a lot of 10-24 screws, but those have too coarse a thread).

The result worked well and has a certain “there-I-fixed-it” charm, but did not really appeal to my wife or me.

I took the scrap of HDPE, cut off a chunk with my new bandsaw, drilled a hole through it with my drill press, put it on my wood lathe (a tool that has sat idle in my garage for at least 20 years), and turned a decorative cover for the screw. HDPE is much easier to turn than wood is—there’s no grain to tear out!

I didn’t quite get the dimensions I wanted—the screw head is wider than the handle rather than matching, but the result is much better that the bare screw.

I still have enough of the scrap to make a couple more attempts, and one of these days I’ll redo the handle to be wider with a flat-head screw countersunk in, rather than a pan head sitting on top.

2017 October 31

Twenty-fifth weight progress report

Filed under: Uncategorized — gasstationwithoutpumps @ 23:04
Tags: , , , , , ,

This post is yet another weight progress report, continuing the previous one, part of a long series since I started in January 2015.


My weight has finally gotten back within my self-imposed target region.

The recent rapid drop is probably due to the Mechatronics class—I have to bicycle up to campus almost daily, and I spend the day in the lab without eating.

The month of October had me riding an average of 5.23 miles a day. I’ll probably keep up almost this level through November, but my trips to campus will drop in December, but come back up in January.

Incidentally my cholesterol level is essentially unchanged several months after switching from 40mg atorvastatin to 20mg rosuvastatin—my HDL/LDL ratio may be slightly better, but that is probably just noise in the measurements.

2017 October 29

Futuristic Lights at Santa Cruz New Tech Meetup

Filed under: Uncategorized — gasstationwithoutpumps @ 21:36
Tags: ,

Zohar Wouk (CEO of Futuristic Lights) will be speaking at the Santa Cruz New Tech Meetup on Wed 1 Nov 2017. The meetup starts at 6pm at Cruzio.

Santa Cruz New Tech MeetUp – November 2017

Wednesday, Nov 1, 2017, 6:00 PM

Cruzio & Ecology Action Green Building
877 Cedar Street Santa Cruz, CA

175 Technologists Attending

David Coulter, Kelly Wachs, Haven, SurfX, Futuristic Lights, Support Logic   We are going cosmic for this event!  Very exciting line up!• How We Got the First Image of a Gravitational Wave Source / David Coulter:   astrophysicists at UCSC led a neutron star shattering discovery this month, validating Einstein’s gravitation wave theory.  Learn wh…

Check out this Meetup →

Incidentally, I understand that Futuristic Lights has finally finished shipping all the pre-ordered Ion glove sets—their new low-cost, high-feature product.

2017 October 25


Filed under: Uncategorized — gasstationwithoutpumps @ 20:10
Tags: , , ,

In Shaving my head, I announced that I would be having my head shaved, but not my beard.

In Shaving my head (and maybe my beard), I offered to let my beard be shaved if the donations came up to $1000.

In Shaving my head, beard, and eyebrows, I announced that my head, beard, and eyebrows would be shaved, and that the next (and last) stretch goal would be shaving my chest hair.  That goal was not reached, so my chest hair is intact.

Here are some photos: before, during, and after the shaving:

This is what I looked like yesterday, before being shaved.

This is what I looked like after being shaved, wearing the silly medal they gave me for raising the most money at the UCSC event.

Just after I’ve been shaved. (photo by Kishwar Shafin)

Another shot of me being shaved (photo by Kishwar Shafin)

Being shaved. (Photo by Kishwar Shafin)

I was a little surprised by how much stubble they left me—it will save me a week on growing the beard back.  In the meantime, my wife has to put up with living with a stranger.

The pictures of me just after being shaved look to me more like my older brother than like me (he is naturally somewhat bald and stays clean-shaven).

I had to adjust the straps on my bicycle helmet before cycling home this evening—the helmet was a size or two too large without the hair and beard as padding.

On the walk home from dinner this evening, I noticed that I had the shadow of a stranger—I wonder who has my shadow.

With $2386 donated from 70 donors, the average donation was just over $30—it makes me feel a bit like Bernie, with lots of small donors!

Although the shaving event is over, you can still contribute to the campaign, either to express amusement at how I look, or (more importantly) to fund research into pediatric cancer, which does not get the research attention that adult cancers get from the government and major foundations.

The link for donating again:

With late donations, the total by 31 Oct 2017 was $2661 donated.  Thanks, everyone!

Next Page »

Create a free website or blog at

%d bloggers like this: