Gas station without pumps

2015 August 2

De-extincting mammoths

Filed under: home school — gasstationwithoutpumps @ 09:48
Tags: , ,

I had posted a picture without much content that was on of my most popular blog posts: Bring back the mammoth! and in April I noticed that Beth Shapiro (a UCSC professor in ancient DNA) had published a book, How to Clone a Mammoth.  My wife bought the book from Bookshop Santa Cruz, and I just finished reading it.

There was not much new technical material in the book for me (I’ve been to several of Beth Shapiro’s and Ed Green’s talks about ancient DNA, and I’ve read papers and heard talks on the CRISPR/CAS9 system for editing DNA), but the book is a well-written description of the technology and of the ethics involved in de-extinction. Dr. Shapiro has a fine sense of humor, so book is highly readable without the dry academic tone that mars many books written by professors.

The reading level of the book is carefully judged to be accessible to most adults (about a high-school reading level), and the content should be accessible to high-school students and advanced middle-school students.  Despite the title, the book does not contain any detailed instructions on the techniques and processes used in recovering ancient DNA or editing genomes (most of which are tedious and difficult even for the grad students and postdocs who do them routinely). It does, however, provide a broad overview of the processes involved, what their limitations are, and why one might want to recover a species from extinction besides the “coolness” factor.

Dr. Shapiro is clearly in favor of de-extincting some species, but is also very clear that what she means by this is not what some people assume. She does not believe that it is possible to bring back mammoths and passenger pigeons as they were originally. What is feasible is to recover some of their lost genes and put them into closely related species (like Asian elephants and band-tailed pigeons), to get a hybrid species that can (perhaps) fill the ecological niches vacated by the extinct species.  That is, we can’t get the original mammoths back, but we may be able to create a mammoth-like elephant that looks like a mammoth and can survive in the cold the way mammoths did.

She makes a good case for the environmental benefits for reintroducing some species to habitats that have lost them—particularly large herbivores like mammoths and giant tortoises, but she also presents the case against reintroduction fairly clearly (though her position is clear).

I highly recommend the book for high-school biology students, particularly home-schooled students, who have time to ponder some of the difficult ethical questions involved in de-extinction.

2015 July 31

Newer dimmer software

Filed under: Uncategorized — gasstationwithoutpumps @ 17:16
Tags: , ,

I just posted yesterday about new software for my PWM dimmers that provides smoother control of the light levels (having 256 levels plus off, rather than 63 levels plus off) with a 256:1 brightness range rather than the approximately 256:6 range of the previous code.

There was a bit of a problem with the lowest light level—it was more like 1/20th as bright as the second highest, rather than 1/2, and it flickered annoyingly. The other low light levels were also rather far apart, causing noticeable steps in brightness for about the first 10 steps.

So today I rewrote the code to have a genuine 512:1 brightness range (plus off), without the super-dim setting. This was a bit tricky to do, because the ATtiny13A has only a single 8-bit counter to use for PWM or any other timing.  I also wanted the minimum on-time for a pulse to be at least 5µs and the maximum PWM period to be less than 5ms.

What I did was to use the 8-bit PWM for the higher brightness levels, but turn it off for 3 PWM periods out of 4 for the low light levels.  I use the timer overflow interrupt to keep track of which PWM period I’m on, and to turn the PWM on or off.  To avoid glitches, I wait until the counter has counted up past the end of the PWM pulse, so that the PWM is only turned on or off when the output is low.  (That’s not quite true—for turning the light off or operating in the top half of brightness, I can switch the PWM mode at any time—it is only when I’m trying to do one out of four PWM periods that I need to be careful about glitches.)

I don’t have a full 1024-bit PWM range.  In addition to OFF, I have 303 light levels, 63 for low light levels (from a duty cycle of 2/1024 to 64/1024 in steps of /1024) and 240 for high light levels (from a duty cycle of 17/256 to 256/256 in steps of 1/256)

The conversion from the linear 10-bit analog-to-digital reading (0–1023) to pulse lengths is done by the following method:

if ADC >= 512
    use SHORT PWM (256)
    expon = ADC>>7
    frac = 0x80 + (ADC & 0x7f)
    pulse_len = 1+ (frac>> (7-expon))
else if ADC >= 8
    use LONG PWM (1024)
    pulse_len = 1 + (ADC >> 3)
else
    turn PWM off

The transition between the short and long PWM periods is evident in a plot of the pulse width and duty cycle:

For the first half of the range, I use a linear scaling for potentiometer to brightness, and for the second half I use a stepwise linear approximation to an exponential.

The minimum pulse width is about 6.7µs, and the long PWM period is about 3.4ms.  There is a trivial modification to allow 1/1024 duty cycle (change the first threshold from 8 to 4), but the shortest pulse is then too short to turn on the LED boards, giving either a very dim light or no light, depending on exactly how low the drain voltage gets in the available time.

I also added some hysteresis to the reading of the analog-to-digital converter, to avoid flicker from digitization noise when the value was near a threshold. The new code is a bit bigger than the previous code (372 bytes instead of 222), but still well below the 1kB limit of the flash.

I’ll need to reprogram the desk lamps again.

Seventh weight progress report

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

In 2015 New Year’s resolution , I said that I want to lose 10–15 pounds by June 2015. In Weight-loss progress report, Second weight-loss progress reportThird weight-loss progress report , Fourth weight-loss progress reportFifth weight-loss progress report, and Sixth weight-loss progress report I provided monthly updates.

My weight was remarkably stable in July, and my average weight since May 1, when I switched from weight loss to weight maintenance is 158 lbs.  I think I’d prefer 157 lbs, but I’m happy with how stable the weight has been and am not going to change any habits to try for an adjustment that is less than the normal random fluctuation in weight.

My weight stayed within my target range for all of July.

My weight stayed within my target range for all of July.

Despite my predictions last month, I bicycled up to campus several times in July, though I only averaged 3.48 miles/day for the month, which is less than the 4.05 miles/day I’ve averaged over the last 400 days.

2015 July 30

Getting KL25Z bootloader to work without Windows 7

Filed under: Circuits course — gasstationwithoutpumps @ 20:26
Tags: , , , , ,

The one thing I hate about the Freedom KL25Z boards is that they are shipped with a bootloader that doesn’t work.  More precisely, they are shipped with a bootloader that works only with Windows 7, not Mac OS X, not Linux, and not even Windows 8.  (Note: never get P&E Micro to do any software work for you—they are responsible for this crappy bootloader.)  There is a newer bootloader from P&E Micro, but you need a Windows 7 computer to download it, so that does no good at all (it’s worse than that: see below).

I bought a new KL25Z board recently, to replace one that my son borrowed for Futuristic Lights, and soldered up the headers today, and was ready to test it out. I was hoping that they were now using one of the newer P&E bootloaders, that supposedly works on Macs (I’ve never seen a P&E bootloader that works with Macs, but I was willing to believe that P&E got enough complaints that they eventually fixed their bugs). Unfortunately, what I got is

MicroBoot Kernel Version is: 1.05
Bootloader Version is: 1.09

but P&E Micro reports

Bootloader versions 1.10 and earlier are not allowing firmware update and MSD FLASH programming on my OpenSDA board, with the Linux, MacOS, or Windows 8/8.1 operating systems.

I understand that on some of their newer boards, Freescale is using the mbed.org bootloader, which is the one I want to install on my KL25Z board. My choices at this point seem to be:

  • Take the 6.5-mile bicycle ride round-trip to campus to use an ancient Windows 7 machine from the circuits lab (this is what I’ve done in the past).
  • Buy a Windows 7 laptop to use at home, for initializing KL25Z boards and for testing PteroDAQ multi-platform support.
  • Look on the web for a workaround.
  • Ask my son if he found a workaround for his Linux laptop.

I’m too lazy to bike to campus (I did that cycle ride 4 times in the last 6 days), and I can’t get a laptop delivered instantly (and it will take quite a bit to put aside my aversion to Windows enough to buy even an $85 used laptop with Windows). That leave the web search and asking my son.

I did find a workaround on the web for Windows 8 [https://community.freescale.com/message/440982#440982]:

Configure “Do not allow locations on removable drives to be added to libraries”  as discussed here: http://answers.microsoft.com/en-us/windows/forum/windows8_1-hardware/how-do-i-prevent-system-volume-information-files/815b0046-d631-4419-a43e-44083a3733f5 and you should be able to do updates from Windows 8.1.

I don’t know whether this workaround works, as I don’t have access to a Windows 8 machine to test it on.

My son pointed me to a workaround that has been posted for Linux systems [http://karibe.co.ke/2014/04/changing-the-firmware-on-freescale-freedom-boards-in-linux/], and that he has used successfully. I tried that on Mac OS X, but the utilities for manipulating mounting of disks is different—you need to use ‘diskutil unmount’ and there is no “modprobe”.

I tried doing the closest corresponding actions on Mac OS X, but they did not work.  I could unmount and mount the disk easily enough (it showed up as /dev/disk1, which can be most easily discovered with ‘diskutil list’), but copying the mbed sda file to the disk still had no effect.

We tried the original script from karibe.co.ke on my son’s Linux laptop, and it worked ok.  We could install the mbed.org firmware (from https://developer.mbed.org/handbook/Firmware-FRDM-KL25Z) using the Linux script with the unmount/mount trick. The mbed software worked as usual to download PteroDAQ to the board.

I think tried some more experimenting. We updated the Bootloader to v1.11, using the latest download from P&E Micro, as pointed to by their OpenSDA page. The update worked, to the extent that the Bootloader reported being v1.11, instead of 1.09, but despite P&E’s claims, it still did not work with Mac OS X. I could not download P&E micro .SDA files nor  the 20140530_k20dx128_kl25z_if_opensda.s19 file from mbed.org.

So we used my son’s Linux laptop again to put the mbed software on the KL25Z board, and I’ll have to be carefully not to get into Bootloader mode unless either he’s around with his laptop or I’m willing to cycle to campus.  (Or I break down and get a junky Windows laptop just for rebooting KL25Z boards.)

My son has been suggesting that we get a junky Windows box, so that he can test out the multi-platform features of PteroDAQ without having to cycle to campus with me.  I might do that while he is away at Ashland next week, if I can find a cheap enough laptop that I believe will actually function.

New dimmer software

Filed under: Uncategorized — gasstationwithoutpumps @ 15:46
Tags: , , , , ,

Based on the success of the stroboscope software, I rewrote the dimmer software for my desk lamp (see LED lamp projects for more about the lamps).  The new software provides smoother control of the light levels (having 256 levels plus off, rather than 63 levels plus off) and now has a 256:1 brightness range rather than the approximately 256:6 range of the previous code.

I removed a lot of the general-purpose crap that was inherited from core13 (which was in turn stripped down from the Arduino core software).  I did not get rid of all of core13, so I could probably take out another 50–100 bytes, but the code is down to 222 bytes (and the ATtiny13A has 1kB of flash, so I’m way below the limit).

The actual brightness range of the new dimmer is a bit more than 256:1, because on the shortest pulse the FET doesn’t turn all the way on.  The pulse duration from the ATtiny13A is approximately 3.4µs times the brightness level (9.6MHz clock divided down by 4 and by 8), but I had deliberately slowed the FET transitions by adding a series resistor to the gate, so that nFET doesn’t finish turning on for 5.2µs (as judged by the end of the Miller plateau on the gate).  So at the lowest brightness level, the nFET does not turn all the way on and the voltage on the drain only gets down to 3.5V, which leaves 5.5V across the LED board—enough to turn on the LED, but with only about 10mA, not 118mA. At this low level, the LEDs sometimes flicker, perhaps as a result of some thermal feedback effects. The all flicker together, so the effect is probably in the dimmer’s nFET, not on the LED boards.

ATtiny output (green) and gate voltage (yellow) at 2V/division and 2µs/division for the shortest pulse length.   The gate voltage has not quite reached the end of the Miller plateau before being discharged again.

ATtiny output (green) and gate voltage (yellow) at 2V/division and 2µs/division for the shortest pulse length. The gate voltage has not quite reached the end of the Miller plateau before being discharged again.

ATtiny output (green) and drain voltage (yellow) at 2V/division and 2µs/division for the shortest pulse length.  The BitScope BS-10 oscilloscope clips the voltage to 5.5V—it actually goes to 9V.

ATtiny output (green) and drain voltage (yellow) at 2V/division and 2µs/division for the shortest pulse length. The BitScope BS-10 oscilloscope clips the voltage to 5.5V—it actually goes to 9V.

At the next brightness level, the drain voltage does drop to 0V for at least 2.4µs and stays low enough for the LED board to be at maximum current (below 2.5V) for at least 5.5µs.  There is an enormous difference in brightness between length 2 and length 1 pulses (more like 1:20 than 1:2), because of the low current for pulse length 1, but for length 2 and longer the steps in brightness are pretty much as one would expect from the pulse lengths.

ATtiny output (green) and gate voltage (yellow) at 2V/division and 2µs/division for the shortest pulse length.   The gate voltage has gone past the end of the Miller plateau and started charging past that point. The Miller plateau is also visible on the discharge as the nFET turns off.

ATtiny output (green) and gate voltage (yellow) at 2V/division and 2µs/division for the shortest pulse length. The gate voltage has gone past the end of the Miller plateau and started charging past that point. The Miller plateau is also visible on the discharge as the nFET turns off.

ATtiny output (green) and drain voltage (yellow) at 2V/division and 2µs/division for the  second shortest pulse length.  The BitScope BS-10 oscilloscope clips the voltage to 5.5V—it actually goes to 9V.  The longer pulses allow the nFET to turn on fully.

ATtiny output (green) and drain voltage (yellow) at 2V/division and 2µs/division for the second shortest pulse length. The BitScope BS-10 oscilloscope clips the voltage to 5.5V—it actually goes to 9V.
The longer pulses allow the nFET to turn on fully.

The conversion from the linear 10-bit analog-to-digital reading (0–1023) to pulse lengths is done by the following method:

expon = ADC>>7
frac = 0x80 + (ADC & 0x7f)
pulse_len = ADC < 0x20? 0:  ADC < 0x40? 1: 1+ (frac>> (7-expon))

The stepwise nature of the brightness at low levels is apparent in a plot of the conversion function:

The steps in brightness are quite visible at the low end, but after the first 10 steps, the differences are small enough not to be easily noticed.

The steps in brightness are quite visible at the low end, but after the first 10 steps, the differences are small enough not to be easily noticed.

Overall, I’m pleased with the rework of the dimmer code. I’ll probably have to solder up another of the dimmer boards this summer, since I’ll want one for the light fixture that I haven’t started building yet and one for the Halloween stroboscope.

Next Page »

The Rubric Theme. Create a free website or blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.

Join 316 other followers

%d bloggers like this: