void ZeroPi::slotSetup(int slot, int fun){ if(fun==SLOT_STEPPER){ stepperInit(slot); }else if(fun==SLOT_MOTOR){ motorInit(slot); } }
void SYSTEM_Initialize(void) { OSCILLATOR_Initialize(); PIN_MANAGER_Initialize(); INTERRUPT_Initialize(); EUSART1_Initialize(); TMR3_Initialize(); TMR5_Initialize(); ADC_Initialize(); I2C2_Initialize(); stepperInit(); }
int main(void) { PORTA.DIRSET = PIN0_bm; PORTA.OUTSET = PIN0_bm; if (!systemSetClk32Mhz()) badInitAlarm(); if (!uartInit(19200, 1, 1)) badInitAlarm(); stepperInit(800, 255, 0, 255); //attach all servos: /* for (uint8_t i = 0; i < SERVO_AMNT; ++i) servoAttach(i, 45);*/ systemInterruptEnable(INT_LOW); sei(); char str[CMD_LENGTH]; while (1) { if (uartLinesReceived() > 0) { uartGetLine(str, CMD_LENGTH); switch (executeCmd(str)) { case BAD_FORMAT: uartWrite("Err - cmd is NaN\r\n"); break; case BAD_ARG: uartWrite("Err - not enough args or NaN\r\n"); break; case BAD_CMD: uartWrite("Err - invalid cmd\r\b"); break; } } } }
void setup () { Serial.begin(57600); Serial.println("Init Start"); PORTC |= _BV(PC_OPTOINT); // tie opt int sensor line hight analogWrite(PIN_MOTOR, MOTOR_OFF); PORTC |= _BV(PC_SHUTTER) | _BV(PC_TENSIONSENSOR); PORTD |= _BV(PD_CAMERAPOWER); DDRD |= _BV(PD_CAMERAPOWER); DDRB |= _BV(PB_LAMP); DDRC |= _BV(PC_SHUTTER); CAMERA_OFF; lampOff(); #ifndef USESTEPPER cli(); TCCR2B |= _BV(CS20); // no prescaler TIFR2 &= ~_BV(TOV2); // clear overflow interrupt flag TIMSK2 |= _BV(TOIE2); // enable counter2 overflow interrupt OCR2A = SERVO_STOP; servoPulse = SERVO_STOP; TCNT2 = 0x00; DDRB |= _BV(PB_SERVO); sei(); #else // USESTEPPER stepperInit(); #endif // USESTEPPER shutterState = 0xaa; #ifdef USEFRAM //Serial.println("Init FRAM"); if (fram.begin()) { Serial.println("FRAM ok"); } framIndex = 0; iqTail = 0; iqHead = 0; #endif // USEFRAM Serial.println("{State:Ready}"); }
void reset() { Serial.println("Reset"); #ifndef USESTEPPER setServo(SERVO_STOP); #else stepperInit(); #endif // USESTEPPER lampOff(); //SHUTTERINT_OFF; CAMERA_OFF; SHUTTER_CLOSE; setMotor(MOTOR_OFF); //motorRewind = MOTOR_OFF; parameter = 0; waitingFor = NONE; verbose = 0; frameCount = 0; //optoIntTimeout = 0; shutterState = 0; #ifdef USEFRAM framIndex = 0; #endif // USEFRAM }
void stepper1Stop(void) { stepperInit(); }
void main(void) { OSCCON = 0x70; initIO(); stepperInit(MOTOR_X); stepperInit(MOTOR_Y); stepperInit(MOTOR_Z); stepperInit(MOTOR_4); TRISCbits.TRISC6 = 0; // Timer 0 interrupt rate = ((48 000 000 MHz / 4) / 4) / 256 = 11 718.7 Hz // rxtimeout = 255/11718.75 = 21.7 msec // Note Timer 2 would allow faster rates if the interrupt processing can be optimized T0CONbits.T0CS = 0; // Internal instruction clock as source for timer 0 T0CONbits.PSA = 0; // Assign prescaler to Timer 0. PSA=1 would be equivalent prescaler 1:1 T0CONbits.T08BIT = 1; // 8 bit T0CONbits.T0PS2 = 0; // Set up prescaler to 1:4 = 001 T0CONbits.T0PS1 = 0; T0CONbits.T0PS0 = 1; // se above T0CONbits.TMR0ON = 1; T0CONbits.T0SE = 1; // high to low (no effect when timer clock coming from instruction clock...) usbcdc_init(); INTCON2bits.TMR0IP = 1; // Make Timer0 high priority INTCON = 0; // Clear interrupt flag bits. INTCONbits.TMR0IE = 1; // Enable Timer 0 interrupts TMR0L = 0; TMR0H = 0; stepperSetMode(MOTOR_X, 0xF, 0, 0, 0, 0); stepperSetMode(MOTOR_Y, 0xF, 0, 0, 0, 0); stepperSetMode(MOTOR_Z, 0xF, 0, 0, 0, 0); stepperSetMode(MOTOR_4, 0xF, 0, 0, 0, 0); INTCONbits.PEIE = 1; INTCONbits.GIE = 1; LED_PIN = 0; while (1) { if (usbcdc_device_state != CONFIGURED) { if (!rx_timeout) { rx_timeout = 255; if (!blink--) { blink = 23; LED_PIN = !LED_PIN; } } } else { if (getMessage()) { LED_PIN=0; processMessage(); //LED_PIN = 1; blink = 12; } else { if (!blink--) { blink = 12; LED_PIN = !LED_PIN; while (UIRbits.TRNIF == 1) UIRbits.TRNIF = 0; usbcdc_read(); } } } } }
Stepper_2BYJ48::Stepper_2BYJ48(int motorPin1, int motorPin2, int motorPin3, int motorPin4) { stepperInit(motorPin1, motorPin2, motorPin3, motorPin4, 5); }
Stepper_2BYJ48::Stepper_2BYJ48(int motorPin1, int motorPin2, int motorPin3, int motorPin4, int revolutionsPerMinute) { stepperInit(motorPin1, motorPin2, motorPin3, motorPin4, revolutionsPerMinute); }