Jump to content

ENCODER Incrementer give me 1 & 4294967295 (SOLVED)


Phatline
 Share

Recommended Posts

SOLUTION:

was only a disply Format thing:

i used %u (unsigned int)  instead of %d (which is signed int)

see the code below: MIOS32_LCD_PrintFormattedString("%u %d %u", encoder, incrementer, enc_value[0]);}

 

 

PROBLEM WAS:

when i turn a ENCODER

left:   incrementer= 4294967295 (should be -1 ?) (this value i see on my LCD)

right: incrementer= 1 (no matter how fast i turn the encoder > that should encrease by faster turns? shouldńt it?

 

 

internet says: 4294967295 says that it may be a negative value  "-1" when i false declared the variable as unsigned (signed meens -1 is possible)

in the code below "s32 incrementer" s stand for "signed" i think...
& when i change to "u32 incrementer" (and in app.h also where it is definied), i still get the same "4294967295"

this is my stripped down CODE:

#include <mios32.h>
#include "app.h"
#include <FreeRTOS.h>
#include <task.h>
#include <queue.h>
 
/////////////////////////////////////////////////////////////////////////////
// Local definitions
// used MIDI port and channel (DEFAULT, USB0, UART0 or UART1)
#define KEYBOARD_MIDI_PORT DEFAULT
#define KEYBOARD_MIDI_CHN  Chn1
#define MIDI_STARTNOTE 36

//Set Encoder NR and Hardware-PIN-out
#define NUM_ENCODERS 5
const mios32_enc_config_t encoders[NUM_ENCODERS] = {//(SR begin with 1, ENC with 0)
  { .cfg.type=DETENTED2, .cfg.speed=FAST, .cfg.speed_par=2, .cfg.sr=1, .cfg.pos=0 },
  { .cfg.type=DETENTED2, .cfg.speed=FAST, .cfg.speed_par=2, .cfg.sr=1, .cfg.pos=2 },
  { .cfg.type=DETENTED2, .cfg.speed=FAST, .cfg.speed_par=2, .cfg.sr=5, .cfg.pos=0 },
  { .cfg.type=DETENTED2, .cfg.speed=FAST, .cfg.speed_par=2, .cfg.sr=5, .cfg.pos=2 },
  { .cfg.type=DETENTED2, .cfg.speed=SLOW, .cfg.speed_par=4, .cfg.sr=4, .cfg.pos=0 },};//Menue Encoder

s32 enc_value[5]= {0};

/////////////////////////////////////////////////////////////////////////////////////////
// Startup INIT
void APP_Init(void){
//initialize encoders
s32 i;
for(i=0; i<NUM_ENCODERS; ++i) MIOS32_ENC_ConfigSet(i, encoders[i]);

.....

////////////////////////////////////////////////////////////////////////////////////////
//Encoder Moved?
void APP_ENC_NotifyChange(u32 encoder, s32 incrementer){
// increment to virtual position and ensure that the value is in range 0..127
s32 value = enc_value[encoder] + incrementer;
if(value < 0){value = 0;}
if(value > 127){value = 127;}
enc_value[encoder] = value;

MIOS32_LCD_Clear();         // clear screen
MIOS32_LCD_CursorSet(0, 0); // X,Y  
MIOS32_LCD_PrintFormattedString("%u %u %u", encoder, incrementer, enc_value[0]);}

I have worked thru the tutorials, >>> i only need 5 Encoders, on different PINs, so i have to declare they by hand and not with a FOR Loop over all Shiftregisters.... this is because i dont use the Tutorial code.

Edited by Phatline
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...