Jump to content

just 16 encoders on a DINx4


julienvoirin
 Share

Recommended Posts

here is the code :

/*

#include "cmios.h" 
#include "pic18f452.h"

// absolute values are stored in this array
unsigned char enc_value[16];

/////////////////////////////////////////////////////////////////////////////
// This function is called by MIOS after startup to initialize the 
// application
/////////////////////////////////////////////////////////////////////////////
void Init(void) __wparam
{
  unsigned char i;

  // set shift register update frequency
  MIOS_SRIO_UpdateFrqSet(1); // ms

  // we need to set at least one IO shift register pair
  MIOS_SRIO_NumberSet(16); // for 128 pins

  // set speed mode for 16 encoders
  for(i=0; i<16; ++i) {
    // available speed modes: SLOW, NORMAL and FAST
    MIOS_ENC_SpeedSet(i, MIOS_ENC_SPEED_SLOW, 2); // encoder, speed mode, divider
  }
}
/////////////////////////////////////////////////////////////////////////////
// This function is called by MIOS in the mainloop when nothing else is to do
/////////////////////////////////////////////////////////////////////////////
void Tick(void) __wparam
{
}

/////////////////////////////////////////////////////////////////////////////
// This function is periodically called by MIOS. The frequency has to be
// initialized with MIOS_Timer_Set
/////////////////////////////////////////////////////////////////////////////
void Timer(void) __wparam
{
}

/////////////////////////////////////////////////////////////////////////////
// This function is called by MIOS when the display content should be 
// initialized. Thats the case during startup and after a temporary message
// has been printed on the screen
/////////////////////////////////////////////////////////////////////////////
void DISPLAY_Init(void) __wparam
{
  MIOS_LCD_Clear();
  MIOS_LCD_CursorSet(0x00);
  MIOS_LCD_PrintCString("Hello World!");
}

/////////////////////////////////////////////////////////////////////////////
//  This function is called in the mainloop when no temporary message is shown
//  on screen. Print the realtime messages here
/////////////////////////////////////////////////////////////////////////////
void DISPLAY_Tick(void) __wparam
{
}

/////////////////////////////////////////////////////////////////////////////
//  This function is called by MIOS when a complete MIDI event has been received
/////////////////////////////////////////////////////////////////////////////
void MPROC_NotifyReceivedEvnt(unsigned char evnt0, unsigned char evnt1, unsigned char evnt2) __wparam
{
}

/////////////////////////////////////////////////////////////////////////////
// This function is called by MIOS when a MIDI event has been received
// which has been specified in the MIOS_MPROC_EVENT_TABLE
/////////////////////////////////////////////////////////////////////////////
void MPROC_NotifyFoundEvent(unsigned entry, unsigned char evnt0, unsigned char evnt1, unsigned char evnt2) __wparam
{
}

/////////////////////////////////////////////////////////////////////////////
// This function is called by MIOS when a MIDI event has not been completly
// received within 2 seconds
/////////////////////////////////////////////////////////////////////////////
void MPROC_NotifyTimeout(void) __wparam
{
}

/////////////////////////////////////////////////////////////////////////////
// This function is called by MIOS when a MIDI byte has been received
/////////////////////////////////////////////////////////////////////////////
void MPROC_NotifyReceivedByte(unsigned char byte) __wparam
{
}

/////////////////////////////////////////////////////////////////////////////
// This function is called by MIOS before the shift register are loaded
/////////////////////////////////////////////////////////////////////////////
void SR_Service_Prepare(void) __wparam
{
}

/////////////////////////////////////////////////////////////////////////////
// This function is called by MIOS after the shift register have been loaded
/////////////////////////////////////////////////////////////////////////////
void SR_Service_Finish(void) __wparam
{
}

/////////////////////////////////////////////////////////////////////////////
// This function is called by MIOS when an button has been toggled
// pin_value is 1 when button released, and 0 when button pressed
/////////////////////////////////////////////////////////////////////////////
void DIN_NotifyToggle(unsigned char pin, unsigned char pin_value) __wparam
{
}

/////////////////////////////////////////////////////////////////////////////
// This function is called by MIOS when an encoder has been moved
// incrementer is positive when encoder has been turned clockwise, else
// it is negative
/////////////////////////////////////////////////////////////////////////////
void ENC_NotifyChange(unsigned char encoder, char incrementer) __wparam
{
  unsigned char new_value;

  // do nothing if encoder number greater than array size
  if( encoder >= sizeof(enc_value) )
    return;

  // add incrementer to absolute value, store result in new_value
  new_value = enc_value[encoder] + incrementer;

  // branch depending on direction
  if( incrementer >= 0 ) {
    // overrun check: if new value >= 0x80, force to 0x7f (127)
    if( new_value >= 0x80 )
      new_value = 0x7f;
  } else {
    // underrun check: if new value >= 0x80, force to 0x00 (0)
    if( new_value >= 0x80 )
      new_value = 0x00;
  }

  // store and send absolute value if it has been changed
  if( new_value != enc_value[encoder] ) {
    enc_value[encoder] = new_value;
    MIOS_MIDI_TxBufferPut(0xb0);           // CC at MIDI Channel #1
    MIOS_MIDI_TxBufferPut(0x10 + encoder); // CC# is 0x10 (16) for first encoder
    MIOS_MIDI_TxBufferPut(new_value);
  }
}

/////////////////////////////////////////////////////////////////////////////
// This function is called by MIOS when a pot has been moved
/////////////////////////////////////////////////////////////////////////////
void AIN_NotifyChange(unsigned char pin, unsigned int pin_value) __wparam
{
}
and i modified the mios.table.inc as this : extract
	;; encoder entry structure
ENC_ENTRY MACRO sr, din_0, mode
	dw	(mode << 8) | (din_0 + 8*(sr-1))
	ENDM	
ENC_EOT	MACRO
	dw	0xffff
	ENDM

	global	_MIOS_ENC_PIN_TABLE

_MIOS_ENC_PIN_TABLE
MIOS_ENC_PIN_TABLE
        ;;        SR  Pin  Mode
        ENC_ENTRY  1,  0,  MIOS_ENC_MODE_DETENTED2   ; V-Pot 1
        ENC_ENTRY  1,  2,  MIOS_ENC_MODE_DETENTED2   ; V-Pot 2
        ENC_ENTRY  1,  4,  MIOS_ENC_MODE_DETENTED2   ; V-Pot 3
        ENC_ENTRY  1,  6,  MIOS_ENC_MODE_DETENTED2   ; V-Pot 4
        ENC_ENTRY  2,  0,  MIOS_ENC_MODE_DETENTED2   ; V-Pot 5
        ENC_ENTRY  2,  2,  MIOS_ENC_MODE_DETENTED2   ; V-Pot 6
        ENC_ENTRY  2,  4,  MIOS_ENC_MODE_DETENTED2   ; V-Pot 7
        ENC_ENTRY  2,  6,  MIOS_ENC_MODE_DETENTED2   ; V-Pot 8
        ENC_ENTRY  3,  0,  MIOS_ENC_MODE_DETENTED2   ; V-Pot 9
        ENC_ENTRY  3,  2,  MIOS_ENC_MODE_DETENTED2   ; V-Pot 10
        ENC_ENTRY  3,  4,  MIOS_ENC_MODE_DETENTED2   ; V-Pot 11
        ENC_ENTRY  3,  6,  MIOS_ENC_MODE_DETENTED2   ; V-Pot 12
        ENC_ENTRY  4,  0,  MIOS_ENC_MODE_DETENTED2   ; V-Pot 13
        ENC_ENTRY  4,  2,  MIOS_ENC_MODE_DETENTED2   ; V-Pot 14
        ENC_ENTRY  4,  4,  MIOS_ENC_MODE_DETENTED2   ; V-Pot 15
        ENC_ENTRY  4,  6,  MIOS_ENC_MODE_DETENTED2   ; V-Pot 16
	;; encoders 17-32
	ENC_EOT
	ENC_EOT
	ENC_EOT

and it doesn't work for encoder 9 to 16 !

why ??

Link to comment
Share on other sites

You're right... I got it mixed up.

I haven't done much MIOS C programming but I don't think you are supposed to edit mios_wrapper.asm

See the code in mios_wrapper.asm


;; ---[ configuration table for rotary encoders ]---
#ifndef DONT_INCLUDE_MIOS_ENC_TABLE
;; dummy table located in $MIOS_PATH/include/asm
;; If the application should use ENC entries,
;; just add "-DDONT_INCLUDE_MIOS_ENC_TABLE" to MIOS_WRAPPER_DEFINES
;; and build the table within the C program with:
;;
;; MIOS_ENC_TABLE {
;;              // sr pin mode
;;  MIOS_ENC_ENTRY(1, 0, MIOS_ENC_MODE_DETENTED), // VPot #1
;;  MIOS_ENC_ENTRY(1, 2, MIOS_ENC_MODE_DETENTED), // VPot #2
;;  MIOS_ENC_ENTRY(1, 4, MIOS_ENC_MODE_DETENTED), // VPot #3
;;  MIOS_ENC_EOT
;; };
;;
;; The MIOS_MT_* macros are defined in $MIOS_PATH/include/c/cmios.h
#include <mios_enc_table.inc>
#endif
[/code]

Therefore you should leave mios_wrapper.asm unmodified, and follow the instructions above, so that it does NOT include mios_enc_table.inc and instead uses what you define in your main.c

At least if you follow the right way to do it, you will have a better starting point to fix the problem if it still exists.

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...