void LockServo() { set_timer1(0); set_timer5(0); prev_t1count = 0; prev_t5count = 0; servo_cmd = 0; cmd_pos = mposition; STATUS.pid_lock = true; STATUS.halt_index = false; STATUS.error = false; STATUS.move_in_prog = false; ypwm = 0; mode = e_hold_mode; }
void ResetServo() { set_timer1(0); set_timer5(0); prev_t1count = 0; prev_t5count = 0; servo_cmd = 0; POSCNT = 0; prev_count = 0; velact.ul = 0; mposition.ul = 0; cmd_pos.ul = 0; mode = e_hold_mode; STATUS.halt_index = false; STATUS.error = false; STATUS.move_in_prog = false; }
int main( void ) { mInit(); mUSBInit(); //mBusInit(); bQueue in_q; bQueue out_q; bQueueInit( &in_q ); bQueueInit( &out_q ); usbIface usb; usbIfaceInit( &usb, &in_q, &out_q ); // Set up midi parser midiParser parser; midiParserInit( &parser, &in_q ); midiMsg msg; picker_setup(); stepper_setup(); set_timer5 (60000,30000,1200); setMode( STEP_HALF ); setSpeedLimits( 65, 200 ); set_speed(m_speed_min); setAccelerationLimit(200); int test=0; // uint16_t pos[]={0,-180,0,-360,0,-540,0,-720,-900,0}; // uint16_t dur[]={1000,1000,1000,1000}; uint16_t pos=0; /* //set_speed(m_speed_min); int i=0; update(0); // TIM_Cmd(TIM5, DISABLE); accStop(); setPosition(0); */ int Sflag=0; //strum_delay(1); while(1) { // test = update(pos); // if(test==1){ // if(Sflag==1){ // strum(); // Sflag=0; // } // } update(pos); usbIfaceReadBytes(&usb); if(midiParserHasMsg(&parser,&msg)){ mGreenTOGGLE; usbIfacePrintf(&usb, "status %02x\n",msg.status); usbIfacePrintf(&usb, "channel %02x\n",msg.channel); usbIfacePrintf(&usb, "data[0] %02x\n",msg.data[0]); usbIfacePrintf(&usb, "data[1] %02x\n\n",msg.data[1]); if(msg.channel == INSTRUMENT_CHANNEL || msg.channel == BOTH_CHANNEL) { if(msg.status==NOTE_ON){ strum(); Sflag=1; switch(msg.data[0]){ case 40: pos = E2; break; case 41: pos = F2; break; case 42: pos = FS2; break; case 43: pos = G2; break; case 44: pos = GS2; break; case 45: pos = A2; break; case 46: pos = AS2; break; case 47: pos = B2; break; case 48: pos = C3; break; case 49: pos = CS3; break; case 50: pos = D3; break; case 51: pos = DS3; break; case 52: pos = E3; break; case 53: pos = F3; break; case 54: pos = FS3; break; case 55: pos = G3; break; case 56: pos = GS3; break; case 57: pos = A3; break; case 58: pos = AS3; break; case 59: pos = B3; break; case 60: pos = C4; break; default: break; /* case 57: pos=A3; break; case 59: pos=B3; break; case 60: pos=C4; break; case 62: pos=D4; break; case 64: pos=E4; break; pos=F4; break; case 67: pos=G4; break; case 69: pos=A4; break; case 71: pos=B4; break; case 72: pos=C5; break; default: break; */ } } } } usbIfaceWriteBytes(&usb); } }