Phatline Posted June 25, 2018 Report Posted June 25, 2018 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: 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 project.zip
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now