2021-09-28 11:27 PM
I got the MCSDK example working, but how can i go further?
Can i write custom code that controls the motor without Motor Pilot?
[STEVAL-SPIN3201 // maxon BLDC motor]
Solved! Go to Solution.
2021-10-01 06:41 AM
Hello @KToth.1
Yes you can !
The generated project contains source code that you are free to change.
All the Algorithm execution is done under interrupt, so the while loop in main.c file is the place where you should start.
All the library API are defined in mc_api.h
Do not hesitate to generate a potentiometer example for instance, and analyse the code.
The implementation of the potentiometer reading is done in a dedicated function called from main.c.
Just be aware that SPIN3201 is quite limited in RAM and Flash, so your applicative code must be pretty small.
Regards
Cedric
2021-10-01 06:41 AM
Hello @KToth.1
Yes you can !
The generated project contains source code that you are free to change.
All the Algorithm execution is done under interrupt, so the while loop in main.c file is the place where you should start.
All the library API are defined in mc_api.h
Do not hesitate to generate a potentiometer example for instance, and analyse the code.
The implementation of the potentiometer reading is done in a dedicated function called from main.c.
Just be aware that SPIN3201 is quite limited in RAM and Flash, so your applicative code must be pretty small.
Regards
Cedric
2021-10-03 11:39 PM
Hey,
Thank you very much!
It already works,
But I'm now searching for a delay/wait function.
How can I implement a delay in this context?
Thanks
Chris
2021-10-04 12:37 AM
Hello,
If it is just a delay, HAL_Delay is your friend :
/**
* @brief This function provides minimum delay (in milliseconds) based
* on variable incremented.
* @note In the default implementation , SysTick timer is the source of time base.
* It is used to generate interrupts at regular time intervals where uwTick
* is incremented.
* @note This function is declared as __weak to be overwritten in case of other
* implementations in user file.
* @param Delay specifies the delay time length, in milliseconds.
* @retval None
*/
__weak void HAL_Delay(uint32_t Delay)
Regards
Cedric
2021-10-04 12:47 AM
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1) // the whole thing repeats
{
MC_ProgramSpeedRampMotor1(100, 100); // must set speed before start
MC_StartMotor1(); // start
while(MC_GetSTMStateMotor1() != RUN) {} // wait until it runs
HAL_Delay(5000); // delay
MC_StopMotor1(); // stop
while(MC_GetSTMStateMotor1() != IDLE) {} // wait until it stops
HAL_Delay(2000); // delay
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
}
/* USER CODE END 3 */
For other people searching for examples ;)
This worked for me (SPIN3201)
2021-10-04 12:49 AM
Thank you :)