Jump to content

Recommended Posts

Posted (edited)

i want the to adjust the exact RPM of my Blender (up to 37500 rpm)

 

via a menu encoder i want to setup the exact hz,

the code displays then the RPM value,

the leds connected to a dout-module begin to flash

the combinations of different Dout-pins to one LED give the led more Current... dont know up to know... maybe i need this.

i now have to adjust the speed off the blender until the rotor seems to not moving anymore

4089_6.jpg

 

some basics?

 

if (RPM==Blinkfrequency) {there will be No Motion}

RPM=Rotation per minute

1minute has 60000ms

RPms=Rotation per ms

1RPM is 60000RPms

38000RPM is 2280000000RPms

u32 range is=4294967295

 

1hz = 60RPM

38000RPM = 633Hz so the maximal range of this strobo will be arround 640hz

 

Frequency=1/Time

Time=1/Frequency

1000hz = 1ms

 

the protone resonance frequency of hydrogen (H) = 61779498184847720448 Hz

the 58 Octave from this is 428.681 Hz

taken from the free m.rauch software: http://aladin24.de/htm/res/index.php

428,681hz = 25720,86 RPM --- this is the speed i want to setup the mixer with water in it.

Time= 1/428,681hz = 0,002161316s x 1000 = 2.1613ms

 

that meens that

void APP_Tick(void)

is not accorate for this, since it is called evy 1ms

 

the standart updaterate ot the

void APP_SRIO_ServicePrepare(void){ //called before the shift register chain is scanned
MIOS32_DOUT_PinSet( 0, LEDvalue[0]);}

is 1,28uS which is accourate enough to handle the LED-Status

 

u32=4294.967.295 wordlength.

        seco.milis.mikro  I think thats enough

 

so set up a timer @1uS rate:

void APP_Init(void){ //initialize
    MIOS32_TIMER_Init(1, 1, Timer, MIOS32_IRQ_PRIO_LOW); //1uS Timer set

 

then count (timecount) to a specific time... when reached: reset the counter, turn on the led...

the counter now counts again a specific time until it reaches the decay--time-mark (here 100uS) now it turn off the LEDs

...now it counts forwarde to the specific time...reset the counter, turn on the led....

void Timer(){
timecount = timecount + 1;
if (timecount >= time) {LEDvalue[0] = 1; timecount = 0;}
if (timecount >= decaytime) {LEDvalue[0] = 0;}}

 

next time some menus, encoders, display, and formulars...

 

for what a ocataved protone resonancy frequency on water? hmm someone sayed that on this frequency the temperature drifts down and water got lost... i want to proove that!

Edited by Phatline
Posted

hmmm... the timer or the shiftregister update are not working as i want... i want a stable blink...instead, it sometimes some blinks dont accour... it looks like the counter overlaps with the shiftregister update or so...maybe it is a priority question --- any idea?

here is the code: (attached is also the full project - it runs on a lp17 core with dio-shiftregisters connected-dout register 1 pin 0 is the blink-output... the din register 1 pin 0+1 = hz-encoder.... the used display is 2x40 signs...)

#include <mios32.h>
#include <FreeRTOS.h>
#include <task.h>
#include "tasks.h"
#include "file.h"
#include "app.h"
#include <portmacro.h>
#include <queue.h>
#include <semphr.h>
#include <string.h>
#include "mios32_timer.h"

#define NUM_ENCODERS 9 //5 Menue Encoders are connectet
const mios32_enc_config_t encoders[NUM_ENCODERS] = {//(SR begin with 1, ENC with 0) // setup the Pinout of that Encoders
	{ .cfg.type=DETENTED2, .cfg.speed=FAST, .cfg.speed_par=4, .cfg.sr=1, .cfg.pos=0 },		//Menue Encoder 0 	- only virtual, since they are mapped to differnt Variables... 
	{ .cfg.type=DETENTED2, .cfg.speed=FAST, .cfg.speed_par=4, .cfg.sr=1, .cfg.pos=2 },		//Menue Encoder 1	- ...if "Menue Page Encoder" has changed
	{ .cfg.type=DETENTED2, .cfg.speed=FAST, .cfg.speed_par=4, .cfg.sr=1, .cfg.pos=4 },		//Menue Encoder 2
	{ .cfg.type=DETENTED2, .cfg.speed=FAST, .cfg.speed_par=4, .cfg.sr=1, .cfg.pos=6 },		//Menue Encoder 3
	{ .cfg.type=DETENTED2, .cfg.speed=FAST, .cfg.speed_par=4, .cfg.sr=2, .cfg.pos=0 },		//Menue Encoder 4 
	{ .cfg.type=DETENTED2, .cfg.speed=FAST, .cfg.speed_par=4, .cfg.sr=2, .cfg.pos=2 },		//Menue Encoder 5
	{ .cfg.type=DETENTED2, .cfg.speed=FAST, .cfg.speed_par=4, .cfg.sr=2, .cfg.pos=4 },		//Menue Encoder 6
	{ .cfg.type=DETENTED2, .cfg.speed=FAST, .cfg.speed_par=4, .cfg.sr=2, .cfg.pos=6 },		//Menue Encoder 7	
	{ .cfg.type=DETENTED2, .cfg.speed=FAST, .cfg.speed_par=4, .cfg.sr=3, .cfg.pos=0 },};	//Menue Page Encoder
xSemaphoreHandle xLCDSemaphore;		// take and give access to LCD

    u32 MenueUpdateCount = 0;
    u32 value = 0; //Encoder calculation...
    u32 i = 0; //Encoder calcualtion

//WKS
  u32 hz = 428;
  u32 nm = 10;
  u32 rpm = 25680;
  u32 time = 2161; //setup timer time
  u32 timecount = 0;
  u32 hzcount = 0;
  u32 decaytime = 128;
    
//Task Prioritys	
#define MUTEX_LCD_TAKE { while( xSemaphoreTakeRecursive(xLCDSemaphore, (portTickType)0) != pdTRUE ); }  //a Mutex reserve a Resoure (LCD or SD-Card) for a task, until it is given away...
#define MUTEX_LCD_GIVE { xSemaphoreGiveRecursive(xLCDSemaphore); }
#define PRIORITY_StoreLoad                        ( tskIDLE_PRIORITY + 2 ) //3:Mios standart

static void StoreLoad(u8 tick, u16 order);		
static void Timer(void);

void APP_Init(void){
	MIOS32_BOARD_LED_Init(0xffffffff);                                  //initialize all LEDs
	xLCDSemaphore 		= xSemaphoreCreateRecursiveMutex();	            //create Mutex for LCD access																									//initialize encoders   i = counter
	for(i=0; i<NUM_ENCODERS; ++i) MIOS32_ENC_ConfigSet(i, encoders[i]); //initialize encoders
    MIOS32_TIMER_Init(1, 1, Timer, MIOS32_IRQ_PRIO_HIGH);               //1uS Timer set
     
MIOS32_SRIO_ScanNumSet(1); // limit the number of DIN/DOUT SRs which will be scanned for faster scan rate

//speed up SPI transfer rate (was MIOS32_SPI_PRESCALER_128, initialized by MIOS32_SRIO_Init())
MIOS32_SPI_TransferModeInit(MIOS32_SRIO_SPI, MIOS32_SPI_MODE_CLK1_PHASE1, MIOS32_SPI_PRESCALER_64);
  // prescaler 64 results into a transfer rate of 1 uS per bit
  // when 2 SRs are transfered, we are able to scan the whole 16x8 matrix in 300 uS
}

void Timer(){
timecount = timecount + 1;
if (timecount > time) {MIOS32_DOUT_PinSet( 0, 1); timecount = 0;}
if (timecount > decaytime) {MIOS32_DOUT_PinSet( 0, 0);}}
 
void APP_Background(void){}

void APP_Tick(void) {  //1ms Event Triggering
MenueUpdateCount = MenueUpdateCount + 1; 
     if(MenueUpdateCount > 650){MenueUpdateCount = 0; StoreLoad(0, 0);}} //update the Menue

void APP_MIDI_Tick(void){}
void APP_MIDI_NotifyPackage(mios32_midi_port_t port, mios32_midi_package_t midi_package){}
void APP_SRIO_ServicePrepare(void){}
void APP_SRIO_ServiceFinish(void){}
void APP_DIN_NotifyToggle(u32 pin, u32 pin_value){}
void APP_ENC_NotifyChange(u32 encoder, s32 incrementer){
	
	if(encoder == 0){
	value = hz + incrementer;                   // increment to virtual position and ensure that the value is in range 0..127
	if(value < 0)   {value = 999;}
	if(value > 999){value = 0;}
	hz = value;

	time = 1000000/hz; //we count in mikro Sekonds!
	rpm = hz * 60;
	}
	
	if(encoder == 2){
	value =  time + incrementer;                   // increment to virtual position and ensure that the value is in range 0..127
	if(value < 0)   {value = 3000;}
	if(value > 3000){value = 0;}
	time = value;
	
	hz = 1000000/time;
	rpm = hz * 60;
	}	
	
	if(encoder == 4){
	value = rpm + incrementer;                   // increment to virtual position and ensure that the value is in range 0..127
	if(value < 0)   {value = 100000;}
	if(value > 100000){value = 0;}
	rpm = value;
	
	hz = rpm / 60;
	time = 1000000/hz;
	}
	
	if(encoder == 7){
	value = (incrementer * 2) + decaytime;                   // increment to virtual position and ensure that the value is in range 0..127
	if(value < 0)   {value = 99999;}
	if(value > 99999){value = 0;}
	decaytime = value;
	}
}

void APP_AIN_NotifyChange(u32 pin, u32 pin_value){ //AIN - - Potentiometer has mooved - - Analog InPut 
}

static void StoreLoad(u8 tick, u16 order){         //Display MENUE, Store+Load Bank & Sys-Config
    if(tick == 0){//Menue
         MUTEX_LCD_TAKE;        //request LCD access
            MIOS32_LCD_Clear(); //clear screen
          //1st Line = Encoder Variables....change something!
            MIOS32_LCD_CursorSet(0,  0);  MIOS32_LCD_PrintFormattedString("%d", hz);
            MIOS32_LCD_CursorSet(10,  0);  MIOS32_LCD_PrintFormattedString("%d", time);
            MIOS32_LCD_CursorSet(20, 0);  MIOS32_LCD_PrintFormattedString("%d", rpm);	
            MIOS32_LCD_CursorSet(35, 0);  MIOS32_LCD_PrintFormattedString("%d", decaytime);
          //2nd Line = Menue Describtio
            MIOS32_LCD_CursorSet(0,  1);  MIOS32_LCD_PrintFormattedString("%s", "hz");
            MIOS32_LCD_CursorSet(10,  1);  MIOS32_LCD_PrintFormattedString("%s", "usec");            
            MIOS32_LCD_CursorSet(20, 1);  MIOS32_LCD_PrintFormattedString("%s", "rpm");           
            MIOS32_LCD_CursorSet(35, 1);  MIOS32_LCD_PrintFormattedString("%s", "decay");            
          MUTEX_LCD_GIVE;}}					// release LCD access for other tasks     

 

RPM_BLINK.zip

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...
×
×
  • Create New...