Jump to content

Custom handling of DIN shift register


Wilba
 Share

Recommended Posts

Hi,

This is directed to Thorsten, but anyone else could help me if they want!

I'm a total newbie to MIOS, but I'm a software engineer so I can appreciate how great it is. TK you're a legend!

However, what I'm currently stuck on is the lack of documentation regarding when MIOS ISRs get called and what you can and can't do in them.

What I want to do is not use USER_DIN_NotifyToggle but rather do my own handler of edge transitions in the DIN shift registers.

I am ASSUMING I can just handle USER_SR_Service_Finish and then call MIOS_DIN_SRGet to get the FSR to point to the start of the "array" containing the captured state of the DIN module's input pins. Then in this handler I can compare to a cache (in my app's memory) and do whatever MIDI I/O I want then - by iterating FSR1, I can compare the before/after state of the captured DIN input pins.

ie. I want more than a toggle handler... I want to do things like "if this switch is currently closed AND another switch becomes closed, then send this MIDI event" etc.

I just want confirmation that (a) USER_SR_Service_Finish gets called between updates of the DIN state in RAM, and (b) I can iterate FSR1 to iterate over that DIN state in RAM (I don't need to call MIOS_DIN_SRGet to access each register, right?)

ALSO, what's the mapping between DIN module pins and the bit positions in registers returned by MIOS_DIN_SRGet?

Apologies if this was already answered on the forum or in a MIOS example...

Thanks,

Wilba

Link to comment
Share on other sites

Hi Wilba,

your assumptions in a) and b) are correct.

USER_SR_Service_Finish gets called directly after the DIN registers have been updated. By using the MIOS_DIN_SRGet function (WREG=0) you will get a pointer to the first register and you can iterate over all 16 registers by incrementing the pointer.

Before USER_SR_Service_Finish will be called, also another usefull array will be updated: SR_DIN_CHANGED which notifies a transition for every single bit. You just only have to add 0x10 to FSR1.

Btw.: if you want to prevent that USER_DIN_NotifyToggle will be triggered, since your own handler already takes care for some pins, just delete the appr. flags which are related to the appr. DIN.

Example:

USER_SR_Service_Finish
        ;; get pointer to first DIN register
        call    MIOS_DIN_SRGet
        ;; add 0x10 to pointer in order to address the DIN_CHANGED register
        movlw   0x10
        addwf   FSR1L, F
        ;; check for transition on input #3, if not, exit
        IFCLR   INDF1, 3, return
        ;; prevent that USER_DIN_NotifyToggle will be triggered
        bcf     INDF1, 3
        ;; switch back to DIN register
        movlw   -0x10
        addwf   FSR1L, F
        ;; branch depending on pin state 
        IFCLR   INDF1, 3, rgoto XXX_0
        rgoto   XXX_1
On the other hand: it would be interesting why you don't plan to use the standard handler --- example for
I want to do things like "if this switch is currently closed AND another switch becomes closed, then send this MIDI event" etc
USER_DIN_NotifyToggle
        ;; branch depending on state of "shift" button (connected to pin #0)
        movlw   0x00
        call    MIOS_DIN_PinGet
        bz      USER_DIN_NotifyToggle_SendCC
        rgoto   USER_DIN_NotifyToggle_SendNote

        ;; ...

Assignments of the pins: bit #0 corresponds to D0 of a shift register, etc.

Best Regards, Thorsten.

Link to comment
Share on other sites

Thanks for the answers TK,

On the other hand: it would be interesting why you don't plan to use the standard handler

OK, since you're interested, I'll explain further...

I've been working on a custom MIDI controller for a few months, using a PIC16F84... until I realised I really needed more I/O pins, A/D conv, more RAM, etc... Came across uCApps/MIOS and now I'm keen to use MIOS and PIC18F452 to do the job. (Also really like the SID project so I'm building one of them too).

The controller is a fretboard design, like a bass guitar. Instead of strings there are touch switches (copper wire) between where the frets would go. There are also plucking/strumming sensors which are an infrared LED/photodiode pair - you break the beam with a finger.

One "mode" just maps presses on the touch sensors to note on events directly - ie. just a keyboard-like interaction. The other mode is guitar-like - ie. you need to strum/pluck to get the note, and while a strum/pluck sensor is down, fret changes trigger notes played legato (with optional portamento) or even retrigger currently held down frets higher up the string, etc.

So the reason why I wouldn't want to do it in a USER_DIN_NotifyToggle handler is because I need to take into account the entire state of all the registers (ie. calculating the "highest" touched fret, comparing to "highest" touched fret last time, calculating velocity from time of partial to full blocking of IR beam, etc.)

It's a bit more complex than "button A AND B" - I was just trying to simplify it to give an example...

Thanks again for your help... I should be able to utilize the SR_DIN_CHANGED array to do all I want.

Regards,

Wilba

Link to comment
Share on other sites

In case you're interested, the controller I'm building is inspired by the Ztar ( http://www.starrlabs.com/ ).

(Check out a video of someone playing one: http://www.shanesanders.com/music2.html )

I'm not copying the Ztar completely, because I can't get my hands on force sensitive switches (on the Ztar, ALL the fretboard buttons are velocity/force sensing!) and I can do without polyphonic aftertouch (not many synths use it anyway).

So the main differences are: 4 "strings" made of touch sensors (ie. zero "action" in guitar-speak), and optical strum/pluck sensors, both concepts already proven in prototyping using PIC16F84... It will have a joystick for pitch bend/expression effects (salvaged from play station controller!) and some other analog input devices.

When it's complete, I plan to share the circuits and source code with the MIDIBox community, in case others are interested in building something similar. (I can't wait to hook it up to the SID and jam with it!)

Wilba

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...