hey,
i have a very time sensitive case, where i have to scan a GPIO (DIN) Pin (J5) for ON/OFF states (audio>schmitt-trigger>J5)
>>> Clock 2 Audio 2 Clock:
< base_url >/topic/20623-midi-stream-to-audio-stream-converter-midi-tape-recording-midi-over-audio/?do=embed
i switched off, what i found, and deleted as many tasks i know… > see code attachment (mios config and app.c)
what task is best for scaning such GPIO? or can i change priority with switch somehwere — i have put it into “void APP_MIDI_Tick” up to now… when a new pulse comes in a midi-clock-send signal goes out also…
the Signal-Pulses on GPIO are 2ms -on-pulses -like shown in this picture
the first and 3rd track are recordet @once where 1st track is audio track,and 3rd track is midi-clock-click, the 2nd track is the overdubbed audio-track driven by the clock of 3rd track — i have 6ms delay… of course there is also some delay in sound generation and other ways.but there is also quite a bit delay in the c-code…
#include \<mios32.h\> u8 clock\_trigger = 0; u8 clock\_counter = 0; u8 audio\_pulse\_durate = 0; u8 Start\_Flag = 1; u8 Mode = 0; //0: Sense Midi Clock, 1: Sense Audio Pulses u8 blink = 0; u8 count = 0; u32 count\_off = 0; u8 loose\_clock = 0; u8 count\_flag = 0; u8 Start\_sense = 0; void APP\_Init(void){ // set GPIO // Set GPIO // J5A0 \>\> DIN - Pull-DOWN - Audio Input \> Sense Pulses from Schmitt Trigger MIOS32\_BOARD\_J5\_PinInit(0, MIOS32\_BOARD\_PIN\_MODE\_INPUT\_PD); // Push Down //connect to 5V // J5A1 \>\> DOUT - Push-Pull - Audio Out \> Generate Pulses for Record MIOS32\_BOARD\_J5\_PinInit(1, MIOS32\_BOARD\_PIN\_MODE\_OUTPUT\_PP); MIOS32\_BOARD\_J5\_PinSet (1, 0); // Turn off PIN \> init // J5A2 \>\> DIN \> Pull-UP - Record Button MIOS32\_BOARD\_J5\_PinInit(2, MIOS32\_BOARD\_PIN\_MODE\_INPUT\_PU); // Pull-UP //connect to ground // J5A3 \>\> DOUT \> Push-Pull - LED MIOS32\_BOARD\_J5\_PinInit(3, MIOS32\_BOARD\_PIN\_MODE\_OUTPUT\_PP); MIOS32\_BOARD\_J5\_PinSet (3, 1); // Turn ON PIN \> init } void APP\_Background(void){ // Switch + LED + MODE (play rec) set + Auto-Stop // /\* //Scan Mode-Switch //deep88 - Switch Version u8 temp = Mode; Mode = MIOS32\_BOARD\_J5\_PinGet(2); if (temp != Mode) { Start\_Flag = 1; audio\_pulse\_durate = 0;} //Mode-LED-States (to indicate Mode-Push-Button if (count \<=0 ) { blink = 0; } if (count \>12){ blink = 1; } if (count \>24){ blink = 0; count =0 ;} if(Mode == 1) { MIOS32\_BOARD\_J5\_PinSet(3, 1);}//Turn OFF PIN - sensing audio pulses dumpout midiclock else if (Mode == 0 && loose\_clock == 1) { MIOS32\_BOARD\_J5\_PinSet(3, 0); }//Turn ON PIN - ready for sensing midiclock - ready for dumpout audio else if (Mode == 0 && loose\_clock == 0) { MIOS32\_BOARD\_J5\_PinSet(3, blink); } //Blink PIN - sensing midiclock dumpout audio if(Mode == 1) { // sensing pulse mode (send out Clock-Mode) // MidiClock Auto-Stop if (count\_flag == 1) { count\_off++; if(count\_off \> 200000) { count\_flag = 0; loose\_clock = 1; count\_off = 0; //turn off blink light after loosing Midi-Connection audio\_pulse\_durate = 0; // Pulse stop duration Start\_Flag = 1; MIOS32\_MIDI\_SendStop(32);//send Stop-Sig - Port-A //MIOS32\_MIDI\_SendDebugMessage("auto-stop"); // DEBUG }}} } void APP\_Tick(void){ // Timer for Pulse-Output Duration if( clock\_trigger == 1 && clock\_counter \<= 1) {clock\_counter++;} else{clock\_trigger =0; MIOS32\_BOARD\_J5\_PinSet(1, 0); }} void APP\_MIDI\_Tick(void){// sensing Audio-Pulses & Dumpout Midiclockdata if(Mode == 1) { // Scan Mode-Switch // First time we get a Pulse, we send out a CLOCK-START-Signal if((MIOS32\_BOARD\_J5\_PinGet(0) == 0) && (audio\_pulse\_durate == 0) && (Start\_Flag == 1) ) { // Pulse = HI, Pulse start duration MIOS32\_MIDI\_SendStart(32);//send Start-Sig - Port-A Start\_Flag = 0; //MIOS32\_MIDI\_SendDebugMessage("start"); // DEBUG } // All other Pulses, are just Clocks, without Startsignals if((MIOS32\_BOARD\_J5\_PinGet(0) == 0) && (audio\_pulse\_durate == 0) && (Start\_Flag == 0) ) {//Pulse = HI, Pulse start duration MIOS32\_MIDI\_SendClock(32);//send MidiClock - Port-A audio\_pulse\_durate = 1; // Pulse starte duration //MIOS32\_MIDI\_SendDebugMessage("clock-durate-pulse"); // DEBUG } // Ensure to kill the PULSE DURATION FLAG, after the Pulse is gone.... if((MIOS32\_BOARD\_J5\_PinGet(0) == 1) && (audio\_pulse\_durate == 1) ) { //Pulse = LO, Pulse still in duration audio\_pulse\_durate = 0; // Pulse stop duration count\_off = 0; // reset Midi-Stop-Signal counter \>\>\> for Autostop count\_flag = 1; // begin to count for Autostop //MIOS32\_MIDI\_SendDebugMessage("pulse-off"); // DEBUG } } } void APP\_MIDI\_NotifyPackage(mios32\_midi\_port\_t port, mios32\_midi\_package\_t midi\_package){ //sense Midi Messages if(Mode == 0&& port==32) { // SEQ Stop Signal if(midi\_package.evnt0 == 252) { Start\_Flag = 1; loose\_clock = 1; Start\_sense = 0; } // when sequencer is stopped: generate midi clock & transport // SEQ Start Signal if(midi\_package.evnt0 == 250|| midi\_package.evnt0 == 251) { Start\_sense = 1; }// start to react on midiclock // SEQ Clock if(midi\_package.evnt0 == 248&&Start\_sense == 1) {//248CLK,250Strt,251Cont,252Stp clock\_trigger = 1; clock\_counter = 0; //initate Clock HI-State Timer MIOS32\_BOARD\_J5\_PinSet(1, 1); //activate GPIO-Pin J5A Pin 2 Start\_Flag = 1; //reset flag in order to send out a start signal when next AUDIO-PULSE COMES IN loose\_clock = 0; count++; } } }
thx for perfomance help
