void stepper_set_output_current(const uint16_t current) { Pin pin = PIN_PWR_DAC; const uint16_t new_current = BETWEEN(VREF_RES_MIN_CURRENT, current, VREF_MAX_CURRENT); if(new_current < VREF_RES_MAX_CURRENT) { pin.type = PIO_OUTPUT_0; pin.attribute = PIO_DEFAULT; PIO_Configure(&pin, 1); DACC_SetConversionData(DACC, SCALE(new_current, VREF_RES_MIN_CURRENT, VREF_RES_MAX_CURRENT, VOLTAGE_MIN_VALUE, VOLTAGE_MAX_VALUE)); } else { DACC_SetConversionData(DACC, SCALE(new_current, VREF_MIN_CURRENT, VREF_MAX_CURRENT, VOLTAGE_MIN_VALUE, VOLTAGE_MAX_VALUE)); pin.type = PIO_INPUT;; pin.attribute = PIO_DEFAULT; PIO_Configure(&pin, 1); } stepper_output_current = new_current; }
void stepper_set_decay(const uint16_t decay) { stepper_decay = decay; DACC_SetConversionData(DACC, SCALE(decay, 0, 0xFFFF, DECAY_MIN_VALUE, DECAY_MAX_VALUE) | (1 << 12)); }
/** * \brief Interrupt handler for SysTick. * */ void SysTick_Handler( void ) { uint16_t value; { if ( 0 == ( ticker%enc.factor) ){ value = sine_data[index_sample++] * amplitude / (MAX_DIGITAL/2) \ + MAX_DIGITAL/2 /*- MAX_DIGITAL/50*/ + BIAS_STEP*bias ; DACC_SetConversionData(DACC, value ) ; DACC->DACC_IER = DACC_IER_EOC; } ticker++; } }
/** * \brief DAC initialization. */ void enc_init(void) { /* initialize amplitude and frequency */ amplitude = MAX_DIGITAL * 2 / 5; frequency = HIJACK_CARRIER_FREQ_CONF; /*10 us timer*/ SysTick_Config( BOARD_MCK / (frequency * SAMPLES) ) ; //_ConfigureTc0( HIJACK_CARRIER_FREQ_8KHZ ); //TC_Start( TC0, 0 ) ; /* Initialize DACC */ DACC_Initialize( DACC, ID_DACC, 0, /* Hardware triggers are disabled */ 0, /* External trigger */ 0, /* Half-Word Transfer */ 0, /* Normal Mode (not sleep mode) */ BOARD_MCK, 8, /* refresh period */ 0, /* Channel 0 selection */ 0, /* Tag Selection Mode disabled */ 16 /* value of the start up time */); /* enable NVIC_DACC. */ NVIC_EnableIRQ( DACC_IRQn ) ; NVIC_SetPriority(DACC_IRQn, 5); /* variable initial. */ enc.data = 0; enc.state = Waiting; enc.cur = SET; enc.factor = Div1; enc.reverse = 0; ticker = 0; index_sample = 0; /*Enable channel for potentiometer*/ DACC_EnableChannel( DACC, DACC_channel_sine ) ; /*initialize the DACC_CDR*/ DACC_SetConversionData( DACC,sine_data[90]*amplitude/(MAX_DIGITAL/2)+MAX_DIGITAL/2); DACC->DACC_IER = DACC_IER_EOC; //Enable DACC end-of-convertion interrupt }