cancel
Showing results for 
Search instead for 
Did you mean: 

How can i write a custom program with ST MC?

KToth.1
Associate II

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]

1 ACCEPTED SOLUTION

Accepted Solutions
cedric H
ST Employee

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

View solution in original post

5 REPLIES 5
cedric H
ST Employee

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

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

cedric H
ST Employee

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

KToth.1
Associate II
  /* 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)

Thank you :)