Hackster is hosting Hackster Holidays, Ep. 6: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Monday!Stream Hackster Holidays, Ep. 6 on Monday!
norths
Published © Apache-2.0

Brushless Motor control _rt_thread

Brushless Motor control _rt_thread

IntermediateFull instructions providedOver 3 days138
Brushless Motor control _rt_thread

Things used in this project

Hardware components

I.MX RT
NXP I.MX RT
×1

Software apps and online services

RT-Thread IoT OS
RT-Thread IoT OS

Story

Read more

Custom parts and enclosures

rt1060-bldc_kBEZTeAl8p.zip

Code

main.c

C/C++
/*
 * Copyright (c) 2006-2023, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2019-04-29     tyustli      first version
 */

//#include "MIMXRT1062.h"
//#include "drv_gpio.h"
//#include "core_cm7.h"
//#include <rtdevice.h>

#include <rtthread.h>
#include "foc.h"

/* defined the LED pin: GPIO1_IO9 */

#define THREAD_PRIORITY         25
#define THREAD_STACK_SIZE       512
#define THREAD_TIMESLICE        5
#define START       0
#define STOP        1
#define IDLE        2


rt_uint32_t state;

static rt_thread_t stateMachine = RT_NULL;
static void stateMachine_entry(void *parameter)
{
    rt_uint32_t count = 0;     
    count ++;
    switch (state)
    {
    		case START:    
		{
			motorMode(START);			
			break;
		}
		case STOP:    
		{
			motorMode(STOP);	
			break;
		}
		case IDLE:    
		{            
			motorMode(IDLE);	
			break;
		}		
		default:
			break;
    }
    //while (1)   { rt_kprintf("stateMachine_entry count: %d\n", count );  rt_thread_mdelay(2000); }    
}


int main(void)
{
    foc_init();

    stateMachine = rt_thread_create("statMachine",
                            stateMachine_entry, RT_NULL,
                            THREAD_STACK_SIZE,
                            THREAD_PRIORITY, THREAD_TIMESLICE);
    if (stateMachine != RT_NULL)
        rt_thread_startup(stateMachine);



}



void commd(int argc, char**argv)
{
    //rt_kprintf("Motor Command init. ");
    rt_kprintf( argv[1]);
    if (!rt_strcmp(argv[1], "start"))
    {
        rt_kprintf("Motor start.\n");
    }
    else if (!rt_strcmp(argv[1], "stop"))
    {
        rt_kprintf("Motor stop.\n");
    }
    else
    {
        rt_kprintf("Motor idle.\n");
    }
}
MSH_CMD_EXPORT(commd, commd m 1)

void reboot(void)
{
    NVIC_SystemReset();
}
MSH_CMD_EXPORT(reboot, reset system)

Credits

norths

norths

7 projects • 2 followers
Fun explorer

Comments