void board_blink_led(led_t led) { switch (led) { case RED: ROM_GPIOPinWrite(LED_RED_PORTBASE, LED_RED, LED_RED); board_delay_ms(LEDBLINKPERIODMS); ROM_GPIOPinWrite(LED_RED_PORTBASE, LED_RED, 0); break; case BLUE: ROM_GPIOPinWrite(LED_BLUE_PORTBASE, LED_BLUE, LED_BLUE); board_delay_ms(LEDBLINKPERIODMS); ROM_GPIOPinWrite(LED_BLUE_PORTBASE, LED_BLUE, 0); break; case GREEN: ROM_GPIOPinWrite(LED_GREEN_PORTBASE, LED_GREEN, LED_GREEN); board_delay_ms(LEDBLINKPERIODMS); ROM_GPIOPinWrite(LED_GREEN_PORTBASE, LED_GREEN, 0); break; default: break; } board_delay_ms(LEDBLINKPERIODMS); }
void board_blink_led(void) { LEDPORT4OUT |=LEDPORT4PIN0; board_delay_ms(LEDBLINKPERIODMS); LEDPORT4OUT &=~LEDPORT4PIN0; board_delay_ms(LEDBLINKPERIODMS); }
static int32_t board_eeprom_enable_eeprom_peripherial(void) { ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_EEPROM0); board_delay_ms (100); return ROM_EEPROMInit(); }
int main (int argc, char **argv) { sys_Init (0, 0); // Turn off WDT, init MCU clocks, ... pin_Config (LED1, GPIO_OUTPUT, 0); // Setup LED1 for output to show activity //-------------------------------------------------------------------- // Configure the L6474 Stepper Ctl chip and the motor attached to it. // This includes downloading configuration parameters into the L6474. //-------------------------------------------------------------------- extern volatile uint8_t numberOfDevices; // used by EasySpin numberOfDevices = 1; // save max # devices for EasySpin logic // ret_code = configure_stepper_motor(); /* Attach the function Error_Handler (defined below) to the error Handler*/ EasySpin_AttachErrorHandler (Error_Handler); /* Attach the function MyFlagInterruptHandler (defined below) to the EXTI IRQ flag interrupt */ EasySpin_AttachFlagInterrupt (MyFlagInterruptHandler); //----------------------------------------- // re-Init of the EasysSpin library //----------------------------------------- EasySpin_Begin (1); //--------------------------------------------------------------- // Read inexistent register to test MyFlagInterruptHandler //--------------------------------------------------------------- /* Try to read an inexistent register. */ /* The flag interrupt should be raised */ /* and the MyFlagInterruptHandler function called */ // EasySpin_CmdGetParam (0, (easySPIN_Registers_t) 0x1F); sys_Delay_Millis (500); /* Move device 0 of 16000 steps in the FORWARD direction */ EasySpin_Move (0, FORWARD, 16000); /* Wait for the motor of device 0 ends moving */ EasySpin_WaitWhileActive(0) ; HAL_Delay (1000); while (1) { //--------------------------------------------------------------------- // MOTION CONTROL // // Perform a repeated sequence of steps, as if we were doing DIY // printing or some other form of positioning/machining sequence. //--------------------------------------------------------------------- //------------------------------------------------------------------ // Setup an initial speed profile and go into full-step mode so that // we can quickly move the stepper to the desired starting position // for machinng something. //------------------------------------------------------------------ /* Select full step mode for the motor */ EasySpin_SelectStepMode (0, easySPIN_STEP_SEL_1); /* Set speed and acceleration to be consistent with full step mode */ EasySpin_SetMaxSpeed (0,100); EasySpin_SetMinSpeed (0,50); EasySpin_SetAcceleration (0,10); EasySpin_SetDeceleration (0,10); /* Move the motor to go position 200 */ EasySpin_GoTo (0,200); /* Wait for the motor to stop moving */ EasySpin_WaitWhileActive (0) ; /* Set the current position of motor to be its "Home" position */ EasySpin_SetHome (0); pin_Toggle (LED1); // show activity - toggle LED //------------------------------------------------------------------ // Now go into 1/16 step mode and set an associated speed profile // so we can machine something //------------------------------------------------------------------ /* Set L6474 to drive motor in 1/16 microstepping mode */ EasySpin_SelectStepMode (0,easySPIN_STEP_SEL_1_16); /* Update speed, acceleration, deceleration for 1/16 microstep mode*/ EasySpin_SetMaxSpeed (0,1600); EasySpin_SetMinSpeed (0,800); EasySpin_SetAcceleration (0,160); EasySpin_SetDeceleration (0,160); pin_Toggle (LED1); // show activity - toggle LED //------------------------------------------------------------------ // Now sweep the motor back and forth several passes as if // machining or printing something. //------------------------------------------------------------------ for (i = 0; i < total_motor_passes; i++) { /* Request motor to step FORWARD to position 6400 */ EasySpin_GoTo (0,6400); /* Wait for motor to stop moving */ EasySpin_WaitWhileActive (0); /* Request motor to step BACKWARD to -6400 position */ EasySpin_GoTo (0,6400); /* Wait for motor to stop moving */ EasySpin_WaitWhileActive (0); pin_Toggle (LED1); // show activity - toggle after each pass } /* In preparation for a new sequence, request Motor to go to Home */ EasySpin_GoHome (0); EasySpin_WaitWhileActive (0) ; board_delay_ms (1000); // pause between sequences } }
void pmrf_delay_ms(uint32_t ms) { board_delay_ms(ms, OSP_DELAY_OS_COMPAT_DISABLE); }
int main (int argc, char **argv) { GPIO_InitTypeDef GPIO_InitStruct; board_init(); // Turn off WDT, init MCU clocks, ... board_systick_timer_config(); // configure 1 ms timer LED1_INIT(); // Setup LED1 for output // LED2_INIT(); // Setup LED2 for output not on STM32 #if (UART_CHECKOUT) while (uart_test1) // TEMP DEBUG of Baud Rate CONSOLE_WRITE ("\n\rInitialization complete. Type in a config parm:\n\r"); while ( ! CONSOLE_CHECK_FOR_INPUT() ) ; // loop till get some data CONSOLE_READ_STRING ((char*) uart_cmd_buf, 12); CONSOLE_WRITE ("Type in a single char: "); ret_code = 0; while (ret_code == 0) // wait till we get a char in ret_code = CONSOLE_GET_CHAR(); CONSOLE_WRITE_CHAR (ret_code); // echo it #endif //------------------------------------------------------------- // Setup GPIOs to operate in Timer/PWM mode // // Start with PA8 (Arduino D7) = TIM1_CH1 //------------------------------------------------------------- /* TIM1 module - Channel 1 output */ GPIO_InitStruct.Pin = GPIO_PIN_8; // PA8 = Arduino D7 GPIO_InitStruct.Alternate = GPIO_AF1_TIM1; // Alt Func = Timer/PWM GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; GPIO_InitStruct.Pull = GPIO_PULLUP; GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; HAL_GPIO_Init (GPIOA, &GPIO_InitStruct); /* TIM1 module - Channel 1 complementary output */ GPIO_InitStruct.Pin = GPIO_PIN_13; // PB13 - not on Arduino - Morpho CN10 - 30 HAL_GPIO_Init (GPIOB, &GPIO_InitStruct); //------------------------------------ // Configure PWM module to be used //------------------------------------ // SystemCoreClock variable holds HCLK frequency and is defined in system_stm32f4xx.c file. uwPeriod = (SystemCoreClock / 20000 ) - 1; // set period = 20 K Hz ret_code = board_pwm_init_module (PWM_MODULE_1, PWM_COUNT_DOWN, uwPeriod, 0); //------------------------------------ // Configure PWM channel(s) to be used //------------------------------------ ret_code = board_pwm_config_channel (PWM_MODULE_1, PWM_CHANNEL_1, (uwPeriod/4), 0); // 25 % duty cycle //--------------------------------------------------- // Enable the PWM module and its associated channels //--------------------------------------------------- ret_code = board_pwm_enable (PWM_MODULE_1, 0); while (1) { // initial checkout - see if PWM is working LED1_TOGGLE(); // show activity board_delay_ms (1000); } // ----- INITIAL CHECKOUT ----- #if (LATER) //------------------------------------------------------------- // Ensure DRV8848 is OFF during config. // setup nSLEEP PB_2 pin (J2-2) to LOW to turn off the DRV8848 //------------------------------------------------------------- pin_Config (Pin19, GPIO_OUTPUT); pin_Low (Pin19); //----------------------------------------------------------------- // Setup PWMs to drive the DRV8711 Stepper //----------------------------------------------------------------- // first, get the period for a 20 K Hz PWM frequency pwm_period = board_frequency_to_period_ticks (PWM_20K_FREQUENCY); // then initialize the needed PWMs, passing in startup period //------------------------------------------------------------- // do basic setup for PWM and Interval Timer (turn on clocks) // Skipping the /32 gives better accuracy (20.004 KHz vs 20.81 K Hz using /32) //------------------------------------------------------------- // MAP_SysCtlPWMClockSet (SYSCTL_PWMDIV_32); // do not do / 32 of Master clock and see results MAP_SysCtlPWMClockSet (SYSCTL_PWMDIV_1); // Setup Master PWM I/O clock MAP_SysCtlPeripheralEnable (SYSCTL_PERIPH_PWM1); // turn on PWM module 1 clock // mg_PWMclock = MAP_SysCtlClockGet() / 32; // save Max PWM Clock value mg_PWMclock = MAP_SysCtlClockGet(); // save Max PWM Clock value mg_Sysclock = MAP_SysCtlClockGet(); // This says 80 MHz nmap_SysClkTicks = MAP_SysCtlClockGet(); // This says 80 MHz after switching over to MAP_ version. // Before that, non MAP_ version was saying 66 MHz, which is whacked out //------------------------------------------------------------------------------ // Setup PWM pins that are used by DRV8848 // // PWM A / AIN1 = PA_4 TA1.2 J2-8 PWM B / BIN1 = PA_6 TA1.1 J1-9 // DIR A / AIN2 = PA_3 TA1CCR2 J2-9 DIR B / BIN2 = PA_7 TA1CCR1 J1-10 // nSLEEP = PB_2 J2-2 nFAULT = PE_0 J2-3 // VREF = PE_4 Adc9 J1-5 //------------------------------------------------------------------------------ // setup DRV8701 STEP_AIN1 PA_6 pin (J1-9) for PWM mode // setup DRV8848 BIN1 PA_6 pin (J1-9) for PWM mode MAP_GPIOPinTypePWM (GPIO_PORTA_BASE, GPIO_PIN_6); // setup BIN1 PWM (J1-9) MAP_GPIOPinConfigure (GPIO_PA6_M1PWM2); //------------------------------------------------ // Setup PWM and associated Count mode. // Tiva only supports DOWN counts, not UP counts //------------------------------------------------ MAP_PWMGenConfigure (PWM1_BASE, PWM_GEN_1, PWM_GEN_MODE_DOWN); // setup default PWM Period and duty cycle mg_PWMperiod = (mg_PWMclock / PWM_20K_FREQUENCY) - 1; // default period /32 = 124 (125 - 1) // default period /1 = 3999 (4000 - 1) MAP_PWMGenPeriodSet (PWM1_BASE, PWM_GEN_1, mg_PWMperiod); MAP_PWMPulseWidthSet (PWM1_BASE, PWM_OUT_2, mg_PWMperiod / 4); // duty of 25 % pwm_duty_value = mg_PWMperiod / 4; // save it for ADC checks //----------------------- // Start up the PWM //----------------------- MAP_PWMGenEnable (PWM1_BASE, PWM_GEN_1); // start up the PWM ??? need ??? MAP_PWMOutputState (PWM1_BASE, PWM_OUT_2_BIT, true); // Enable PWM pin output //----------------------------------------- // setup DIR BIN2 PA_7 pin (J1-10) to LOW //----------------------------------------- pin_Config (Pin10, GPIO_OUTPUT); // setup BIN2 DIR (J1-10) pin_Low (Pin10); //----------------------------------------- // Turn off AIN1 PWM and AIN2 DIR pins PA_4 / PA_3 pins (J2-8/J2-9) to LOW //----------------------------------------- pin_Config (Pin13, GPIO_OUTPUT); // setup AIN1 PWM (J2-8) pin_Low (Pin13); pin_Config (Pin12, GPIO_OUTPUT); // setup AIN2 DIR (J2-9) pin_Low (Pin12); //------------------------------------------------------------- // set nSLEEP PB_2 pin (J2-2) to HIGH to turn on the DRV8848 //------------------------------------------------------------- pin_High (Pin19); while (1) { // LED1_TOGGLE(); // Setup LED1 for output if (adc_Check_All_Complete()) { // we have a completed ADC reading. Pull in the latest reading adc_Read (&adc_value); if ( (adc_value > (adc_cur_value +10)) || (adc_value < (adc_cur_value - 1)) ) { // we have a major change in valu. Update the PWM adc_cur_value = adc_value; // scale the PWM Duty_Cycle (o - 4000) value to match the ADC value (0-4096) if (adc_cur_value > 3999) pwm_duty_value = 3999; else pwm_duty_value = adc_value; // set the new PWM duty ccyle MAP_PWMPulseWidthSet (PWM1_BASE, PWM_OUT_2, pwm_duty_value); // start a new ADC sampling cycle adc_Trigger_Start(); } } board_delay_ms (250); // wait 250 ms (1/4 sec) between samples } #endif }