BLDC control on ATAVRMC303 with ATxMega128A1
main.c File Reference

,v More...

#include "config.h"
#include "mc_interface.h"
#include "mc_control.h"
#include "mc_drv.h"
#include "DB101_IF.h"
#include "adc_drv.h"
#include "uart\uart_lib.h"
#include "ushell_task.h"
#include "clksys_driver.h"
Include dependency graph for main.c:

Go to the source code of this file.

Functions

void clock_init (void)
 
int main (void)
 Main Entry. More...
 

Variables

U16 g_regulation_period = 0
 Define the sampling period. More...
 
Bool g_tick
 Use for control the sampling period value. More...
 
U16 motor_speed = 0
 User Speed Order. More...
 

Detailed Description

,v

Copyright (c) 2008 Atmel.

Main module : It is based on an infinite loop

Version
1.21

Definition in file main.c.

Function Documentation

◆ clock_init()

void clock_init ( void  )

Definition at line 34 of file main.c.

References CLKSYS_Enable, CLKSYS_IsReady, CLKSYS_Main_ClockSource_Select(), CLKSYS_PLL_Config(), and CLKSYS_Prescalers_Config().

Referenced by main().

35 {
36  /* Set system clock to 32MHz. */
37  CLKSYS_Enable(OSC_RC32MEN_bm);//CLKSYS_Enable(OSC_XOSCEN_bm);
38  do {} while ( CLKSYS_IsReady( OSC_RC32MRDY_bm ) == 0 );//do {} while ( CLKSYS_IsReady( OSC_XOSCRDY_bm ) == 0 );
39 
40  CLKSYS_PLL_Config( OSC_PLLSRC_RC32M_gc, 16 );//CLKSYS_PLL_Config( OSC_PLLSRC_XOSC_gc, 4 );
41  CLKSYS_Enable(OSC_PLLEN_bm);
42  CLKSYS_Prescalers_Config(CLK_PSADIV_1_gc, CLK_PSBCDIV_2_2_gc);
43  do {} while ( CLKSYS_IsReady( OSC_PLLRDY_bm ) == 0 );
44  CLKSYS_Main_ClockSource_Select( CLK_SCLKSEL_PLL_gc );
45 }
void CLKSYS_Prescalers_Config(CLK_PSADIV_t PSAfactor, CLK_PSBCDIV_t PSBCfactor)
This function changes the prescaler configuration.
#define CLKSYS_Enable(_oscSel)
This macro enables the selected oscillator.
Definition: clksys_driver.h:81
void CLKSYS_PLL_Config(OSC_PLLSRC_t clockSource, uint8_t factor)
This function configures the internal high-frequency PLL.
uint8_t CLKSYS_Main_ClockSource_Select(CLK_SCLKSEL_t clockSource)
This function selects the main system clock source.
#define CLKSYS_IsReady(_oscSel)
This macro check if selected oscillator is ready.
Definition: clksys_driver.h:94
Here is the call graph for this function:

◆ main()

int main ( void  )

Main Entry.

The main entry point for the control motor application.
The mc_regulation_loop() function is launched every 80ms.

Definition at line 53 of file main.c.

References clock_init(), g_regulation_period, g_tick, mc_ADC_Scheduler(), mc_get_potentiometer_value(), mc_init(), mc_inrush_task(), mc_regulation_loop(), mci_run(), mci_set_motor_speed(), UpdateScreen(), ushell_active, ushell_task(), and ushell_task_init().

54 {
55 
56  clock_init();
57  // init motor
58  mc_init(); // launch initialization of the motor application
59 
60  //init_adc();
61 
62  // Initialyze the communication system for External Command through Uart
64 
65  // Start the motor
67  mci_run();
68 
69  PMIC.CTRL |= PMIC_LOLVLEX_bm;
70  __enable_interrupt();
71 
72 
73  while(1)
74  {
75 
76  // Launch regulation loop
77  // Timer 1 generate an IT (g_tick) all 250us
78  // Sampling period = n * 250us
79  if (g_tick == TRUE)
80  {
81  g_tick = FALSE;
84  if ( g_regulation_period >= 1000 ) //n * 250us = Te
85  {
87 
88  if (ushell_active == FALSE)
89  {
90  // Set User Speed Command with potentiometer
92  }
93  mc_regulation_loop(); // launch regulation loop
94 #ifdef DB101
95  UpdateScreen();
96 #endif
97  }
98  ushell_task();
99  mc_inrush_task(); /* manage the inrush current */
100  }
101 
102  // Show PSC state according to the Over Current information
103  //if(PCTL2 & (1<<PRUN2)) switch_OFF_LED();// PSC ON
104  //else switch_ON_LED();//PSC OFF => Over_Current
105  }
106 }
volatile Bool ushell_active
Definition: ushell_task.c:39
void ushell_task_init(void)
This function initializes the hardware/software ressources required for ushell task.
Definition: ushell_task.c:66
void mci_set_motor_speed(U8 speed)
Definition: mc_interface.c:108
void UpdateScreen(void)
Definition: DB101_IF.c:22
U16 g_regulation_period
Define the sampling period.
Definition: main.c:30
Bool g_tick
Use for control the sampling period value.
Definition: mc_drv.c:39
void clock_init(void)
Definition: main.c:34
void mc_init()
use to init programm
Definition: mc_interface.c:92
void mc_inrush_task(void)
the purpose of this function is to manage the delay used when the overcurrent detection is disabled...
Definition: mc_drv.c:431
void mci_run(void)
mci_run run the motor with parameter
Definition: mc_interface.c:34
void mc_regulation_loop()
launch speed control or no regulation
Definition: mc_control.c:159
void mc_ADC_Scheduler(void)
Launch the scheduler for the ADC.
Definition: mc_drv.c:388
U8 mc_get_potentiometer_value(void)
Get the potentiometer value.
Definition: mc_interface.c:199
void ushell_task(void)
Entry point of the explorer task management.
Definition: ushell_task.c:93
Here is the call graph for this function:

Variable Documentation

◆ g_regulation_period

U16 g_regulation_period = 0

Define the sampling period.

Definition at line 30 of file main.c.

Referenced by main().

◆ g_tick

Bool g_tick

Use for control the sampling period value.

Definition at line 39 of file mc_drv.c.

Referenced by launch_sampling_period(), and main().

◆ motor_speed

U16 motor_speed = 0

User Speed Order.

Definition at line 31 of file main.c.