Close

On gossamer wings we fly

A project log for Feather Op Amp Lab

A custom Feather with SAM L21 microcontroller, paired with wings that let us interactively explore its integrated op amp peripheral.

joey-castillojoey castillo 05/23/2023 at 22:390 Comments

There's a little white lie in the photo that I first posted to the project page. It depicts an OLED screen with a robust UI for operating the Feather Op Amp Lab, but the truth of it is, it's not exactly real. Oh sure, it ran on the L21 Feather, and it output those pixels to the SH1107 OLED, garbled top row and all. But it's a sketch I put together in Arduino that more or less just drew stuff to the screen. Getting the analog stuff to work in Arduinoland was uncharted territory.

To be clear, an Arduino core does exist for the SAM L21. Alas, the mere fact of it having to operate in the Arduino ecosystem means that it makes some choices that I wouldn't necessarily make myself. For a long time those were choices I could live with. But now I'm coming to a point where I need to build my own framework from whole cloth in order to do the things I want to do. 

That's where gossamer comes in. 

The gist of gossamer is simple: I work with Microchip's SAM series chips up and down the product line, from the minimalist SAM D11 to the LCD-oriented SAM L22, with a ton of SAM D21 projects as I'm sure you all have too. The gossamer framework aims to unify all of these platforms with a setup that's consistent, simple and appropriate for low power applications. Over the next six months, I expect gossamer to power projects that range from public art to to field data collection. 

…and of course the Feather Op Amp Lab. 

The Scope

Gossamer targets four chips at this time: the SAM D11, D21, L21 and L22. These chips are all strikingly similar: they all have Cortex M0+ cores and familiar peripherals like ADC's, TCC's and SERCOMs. Alas, a lot of the interfaces to these peripherals have slight differences, and at startup, these chips have subtly different setups.

Gossamer simplifies this by giving us a consistent environment on all four platforms:

Peripherals provide sensible defaults, and are automatically clocked from the source that makes the most sense (i.e. RTC from GCLK3, EIC from GCLK2). Gossamer also provides a consistent method for flashing code to a device: running make && make install builds your application and flashes it to a device using a USB bootloader.

Finally — the most important part of this log — peripheral drivers are generally thin wrappers around the actual hardware, and provide a consistent way to enable, disable and operate those peripherals. 

Peripherals like the OPAMP.

A short and sweet OPAMP driver

The OPAMP peripheral on the SAM L21 is actually astonishingly simple. You enable it, you configure each of the three op amps, and then you turn them on. The actual analog connections are of course more interesting, but for that you can check this excellent application note that describes how to configure the op amps as voltage followers, programmable gain amplifiers, comparators and more. But when it comes to writing code that drives the op amps, this driver does it all in under 100 lines of code.

And as far as making use of the op amp peripheral? This code in our setup function is all we need to create one non-inverting PGA: 

void app_setup(void) {
    HAL_GPIO_A4_pmuxen(HAL_GPIO_PMUX_B);
    HAL_GPIO_A5_pmuxen(HAL_GPIO_PMUX_B);
    opamp_init();
    opamp_set_muxpos (0, OPAMP_MUXPOS_POS);
    opamp_set_muxneg(0, OPAMP_MUXNEG_LADDER) ;
    opamp_set_res1mux(0, OPAMP_RES1MUX_GND);
    opamp_set_res2mux(0, OPAMP_RES2MUX_OUT) ;
    opamp_set_potmux(0, OPAMP_POTMUX_RATIO_14_2) ;
    opamp_enable(0);
}

Set the pin mux to make the pins analog, init the op amp and configure it. With this setup, and a single wire coupled to the op amp's positive input, I was able to amplify the millivolt-level 60 Hz hum in my lab to a 3-volt peak-to-peak signal at the op amp's output pin.

When I told my roommate this, he wasn't all that impressed; most of the time, he pointed out, we're trying to get rid of that infernal hum. Still: with this lightweight framework and a few lines of code, we've proved out the analog aspects of this Feather Op Amp Lab, and laid the groundwork for what's to come.

Discussions