Unused WTPA2 Atmega pins

Hi there,

i am thinking of adding a simple lowpass filter to my wtpa2. (something like "eric archer vcf", shruthi filterboard etc.)
now i had a look at the schematics and noticed that there seem to be two unused pins from the atmega. (pin 28,29 / JP1, JP2)
gave me the idea one of those could be used to output a short trigger whenever a sample starts (and when it restarts in loop mode).
i would use it to make a simple decay envelope out of it that modulates my filter.
something like this could also be used to feed a trigger to a modular system.

i am kind of a noob when it comes to programming though. (only did some picaxe and very little arduino)
i had a look at the code anyways, but i would need help doing the software side of this.

what do you guys think?
has anybody else plans to use these pins?


  • Those pins are for doing EXACTLY that sort of thing.
    Code would be pretty easy to implement.

    Turn the pins into outputs:

    Then in the audio handler, turn one of the pins high if the loop condition is met:

    And bring it low when the loop condition is not met:
    Also bring it low when playback is stopped, so it doesn't hang high in edge cases.

    There are two pins, so you could use one for bank0 samples and one for bank1 samples.


  • thats great. thanks todd!

    i'll try that as soon as my kit gets here.

  • ok great. i managed to build and programm from source without to much trouble.
    now i'll dig into the code.
    there are probably some noob questions ahead...

  • turns out my c skills are not that terribly noobish after all. i am not totally lost and i (kind of) get what is going on.

    i already have PC6 making a tiny pulse when the sample in bank0 restarts its loop. yay!  :)  (i think the pulse is 1 sample long - i'll think later about wether that is long enough for the hardware side of things)
    i turn the pin to high in here and turn it off in the else case

    i put a little extra variable "loopPin" in the BANK_STATE struct to be able to have a separate pin for each Bank.

    so far so good

    the problem i am facing right now is that PC7 is already being used. comments say it is used to be able to messure isrs time. (and my scope shows a bunch of fast pulses on that pin)
    "// Keep the switch OE high (hi z) (PC3), test pin high (PC7 used to time isrs), and the unused pins (PC4-6) low, and put the high addy bits on 0-2.  NOTE -- PC5 is card detect"
    the lines with that comment are:
    PORTC=(0xA8|((unsigned char)(theAddy>>16)&0x07));
    if i understand that right it does the following:
    "write to C-Port:  0xA8 (=10101000) OR the last 3 Bits of (theAddy>>16)"
    am i right in that the part messing with PC7 is in the 0xA8 portion of that??
    bit7 beeing set to high?
    ... and that it also sets PC6 to low?

    am i maybe confusing the order in which the bits are counted? bit0 is the least significant one and bit7 the most significant, right?

    my brain is a bit confused right now. so i'll make a coffee :)

  • That's correct.  You got 0xA8 right, and you're putting the high three bits of the SRAM address onto the bottom three bits of PORTC.
    So PC7 is set high by that line and PC6 is set low.

    PC6 and 7 might have stuff hanging around in the code, but that ISR timing was for my own sake trying to benchmark the code and is not a feature of WTPA right now.

    And yep, bit 7 is the MSb and bit 0 is the LSb.

    Sounds like you're almost there!  Keep it up.


  • nice. thanks.

    i'll get on it tomorrow  and report back soon.
  • Awesome. Very interested in this too. Programming skills like a buffalo though hehe
  • Great.  Get it working and I'll put it back into the next firmware build!
    I've got some other stuff that should go in, too, mostly MIDI related.


  • looks like i got it working.

    have some more testing to do and breadboard a little circuit to test around with it.
    i'll share my code as soon as i am confident everything is working right.

    might not be a big think for somebody who has experience programming, but it boosted my c confidence a lot :)

    discovering the wtpa and reading the forum some years ago was what got me really startet with (s)diy. i think it was here that i found out about mutable instruments.
    ... i planed on getting the wtpa as my first kit, then decided to wait for wtpa2 and when that took time i got a shruthi first. (which i screwd up - filterboard still not working) ....then another. did some stuff on perfboard... did some gieskes kits... then another shruthi.... bought a avr programmer... then ambika ..... got a picaxe programmer ... LXR... learned about bending 90s video devices...  got pulled into eurorack diy.... learned how to solder smt ...  learned how to etch pcbs ...
    and now that wtpa2 is finally out i am actually able to contribute with a little firmware mod.  feels great!
    i owe it all to the sdiy community <3

  • ok here is my code: wtpa_loderbast001.zip
    only globals.h and wtpa.c have changed.
    i put "//loderbast:" everywhere i changed something in a comment so you can use search to find my changes.

    at the moment triggers are only generated in loop mode. after playing in oneshot mode the pin stays high while playback is stopped. not sure if i keep this might be a feature in some usecases but i have not thought about it much yet.

    also at the moment no triggers a generated in overdub mode. i might change that later. 

    i also encountered a bug that seems hard to reproduce: sometimes when sample start, end or windows settings are != 0 and overdub mode is on the wtpa2 outsputs noise at the point it should be looping. probably playback jumps to some randome memory location instead of beeing set to the start point.+
    when you exit overdub mode all is fine again.
    it is hard to reproduce though.
    i suspect this is not something i have broken, because i read something about it in one of your comments, todd.

    another thing i noticed. (unrelated) when loading a sample from sd, a visual feedback (for example led7 stop blinking) would be nice when the sample is loaded. sometimes it does not load the sample when i exit sd card mode after telling it to load. (probably because loading is not done yet.)

  • edited January 2015
    made some progress creating a little release envelope and connecting a shruthi filterboard. here is a little (not very musical) demo
  • Nice work mate.
  • Very nice work! I'll get your code in and check on overdubbing. I've actually noticed overdub problems as well, even with unadjusted samples.
  • i haven't done any work on this in the last days but been thinking about where to go with it.

    what do you guys think how the triggers should act?

    trigger when looping only?
    trigger on start, and when looping?

    one for bank0, one for bank1
    or one for trigger the other for gate?

    would you want to use them to connect to your modular or for mods/added fx you'd put inside the wtpa enclosure?

  • One trigger per bank at sample start (one shot or loop the same) would be great. That would be enough to trigger events in modular like envelopes, or sequence start/ reset
  • ...it took ages, but i am finally back at it. (been bussy with other diy..)

    i have decided that i want multiple gates per loop round and figured out a way of implementing this even with adjustable "clock divider".
    problem is, i seem to run out of cpu.

    i have it down to one long int increment and one if with modulo division of two long ints in the expression (per bank at sample rate). this seems to be way to much. if i don't find a way to optimize the code, drop features or find another alorythm i think it is not going to happen.

    i'll still have to think about it though.

    in the worst case i think i'll just output one trigger and use a tap tempo lfo (http://electricdruid.net/tap-tempo-lfo-taplfo-v2d/) to multiply the frequency. (wouldn't work exactly right while twiddeling the looplength or pitch of course.)

    another idea i had which would be kind of overkill is to send the loop length to another atmega or picaxe or something whenever it changes and flip the putput pin at every sample. then count the impulses with the 2nd processor and have it generate my gates. (might work if the device is fast enough but would be kind of silly.)

    @todd: is there a way of messuring or calculating if my code is too slow without toggeling a pin and messuring with an oscilloscope??
    the way i did it so far is listening if the pith drops when i play / start the 2nd bank.

    @ rosch. if you still want a simple trigger per bank i can do that even if my other plans works out.

  • If you have some hardware timers left, you could do this that way.
    Something like:

    ONLY When the sample starts, get its length (in samples).
    Divide it by number of gates you want per loop, call it "timeBetweenGates" or something.  This will be your target number.
    Set a volatile counter to 0 (gateOutputTimer, say) in the ISR.

    Now, each ISR, increment gateOutputTimer and compare gateOutputTimer to timeBetweenGates.  If they are equal, send your gate pin high and set your counter to 0.
    Otherwise send your gate pin low.
    Optionally, set your counter to 0 each time the sample loops (so you won't drift).  You will have a gate which goes high for one sample at the division you picked.

    No divisions or mods needed that way, just a compare.  Try to avoid using "long" if you can, it's slow (but much faster than a div or mod).  If WTPA2 has 512k of memory max, if you have 8 gates per loop (or more), you can get away with AVR's ints (16 bits) as opposed to longs.

    Good luck!

  • thanks a lot for your ideas, Todd!!!
    i think i got it working 98%.
    i am now in the process of finishing the hardware part of things and fitting everything inside my enclosure.

    i will be a few days before i'll have time to work on it again, but i'll post my results when i am done :)

    cheers Paul

  • i am kind of done and i posted a video in the showoff thread :)
  • @lodeblast -- Checked it out.  Nice work.  It sounds really cool.
  • since i built my wtpa2 some time has passed and i have used it in its "kind of working how i want" state and never looked at the firmware again.
    a few days ago kogz23 asked me for my firmware and how i did the envelope for my filter so i decided to put the stuff i have in here and hope it helps anybody who wants to improve it or do something similar.
    unfortunately i did't document the whole thing very good....

    i did a little circuit an perfboard which connects the wtpa2 to a eric archer vcf (which i had laying around).
    it basically buffers a gate i get from the unused wtpa2 pin; puts it through a clock divider and  gates a basic AD envelope with the output.
    the envelope is a very simple design. (┬┤same principle as this: http://www.hexinverter.net/the-postman/)

    i only have this drawing of the schematic, which i did afterwards and which might not represent exactly what i ended up with. i probably used tl072 opamp (because thats what i had) and cmos logic ICs.

    for the firmware i think i only changed the wtpa2.c file. i don't remember exactly what is happening there, but at least i marked all  my changes with a comment ("//loderbast:") and commented most lines i changed. i used a avr programmer insted of the audio firmware upload so i never created a audio file of my firmware.

    it outputs a kind of clock when a sample is playing. its frequency is dependant on the sample length and pitch.
    it flips the pin high/low something like 8 times a pass through the loop. (i dont remember the exact number)
    so it might not be in time with the rest of the music, but should be in time if the sample length matches the tempo.
    at the moment it only works for one chanel i think.

    for digital inputs from the modular to the play/ rec function of my wtpa2 i don't have a schematic but it is only one resistor and one npn transistor per input.
    i basically pull the rec and play buttons of the wtpa2 low with a npn transistor. and have the input going into the base of the transisor. (collector -> button; emmiter -> ground; base -> input through something like a 10k resistor)
    this way i cannot use the normal controlls of the wtpa2 propperly while something is connected to these inputs. (because the buttons get "pressed" automatically) but it still works to record sampled which loop exactly or start playback in time.

    i also found and uploaded the file i used to do my panel (in case that is of help to anybody)

    i know this is not a lot of information (which is why i didn't post it before) but i hope it helps you kogz23 and we see more of these unused pins put to use in the future:)

  • Thanks very much Loderbast! Much appreciated. I will have a look into how I might be able to implement this into my build, which has a Wasp filter added. So it looks like there will be control of attack and decay? Cool!

  • Thanks, @loderblast!  You're now among the few and proud to contribute to the WTPA2 codebase.
    And thanks for posting here.

    In the event I ever fix the handful of small things I should one day get around to fixing I'll include that loop-to-trigger functionality in the main branch.

    Thanks again,
  • @korgz23: yes. the way i did mine it has pots for attack and decay :)
    as described above my analog circuitry is kind of hacked together. you should probably use at least a rail to rail opamp for the envelope if you do it similar to my schematic. (if you want 0-5V for the Envelope)

    @ToddBailey: Thanks! looking forward to a firmware update ;)

    cheers Paul
Sign In or Register to comment.