Cov txheej txheem:

Plaub Ntsis Oscilloscope: 6 Kauj Ruam
Plaub Ntsis Oscilloscope: 6 Kauj Ruam

Video: Plaub Ntsis Oscilloscope: 6 Kauj Ruam

Video: Plaub Ntsis Oscilloscope: 6 Kauj Ruam
Video: Проект программирования Python-Примеры проектов Python-Эпиз... 2024, Hlis ntuj nqeg
Anonim
Plaub Ntsis Oscilloscope
Plaub Ntsis Oscilloscope

Nws yog qhov kev lom zem-phiaj xwm tsuas yog pom deb li cas hauv qhov nrawm Kuv tuaj yeem thawb MAX7219 dot matrix zaub. Thiab tsis txhob siv nws los ua "kev ua si ntawm lub neej", Kuv txiav txim siab los ua "thaj tsam" nrog nws. Raws li koj yuav nkag siab los ntawm lub npe, qhov no tsis yog hloov pauv rau oscilloscope tiag:-).

Raws li kuv tsis npaj yuav siv qhov no nyob rau hauv ib txoj hauv kev loj, Kuv yuav tsis ua daim ntawv luam tawm Circuit Board rau nws. Tej zaum, tsuas yog tej zaum kuv yuav muab nws tso rau ntawm daim ntawv ntxig tab sis tam sim no nws yog, thiab yuav nyob, ntawm lub khob cij. Tsis tas li ntawd tsis muaj lub tshuab hluav taws xob nkag/txo qis, koj yuav tsum muab lub teeb liab nruab nrab ntawm 0 thiab 3.3V, tsis txhob mus tsis zoo lossis ntau dua 3.3V vim koj yuav ua rau lub microcontroller puas.

Kauj ruam 1: Kho vajtse

Kho vajtse
Kho vajtse
Kho vajtse
Kho vajtse
Kho vajtse
Kho vajtse

Nws pheej yig, pheej yig heev thaum koj yuav cov khoom hauv Suav teb los ntawm ebay lossis cov chaw zoo sib xws. Nws siv pawg tswj hwm kev txhim kho STM32F103C8, qee zaum hu ua "ntsiav tshuaj xiav" uas kuv tau yuav rau ib puag ncig 2 euro (lossis USD, lawv yuav luag zoo ib yam, kawg xyoo 2018), ob qho 8x8x4 dot-matrix qhia nrog MAX7219 chips rau nws, yuav rau 5 euro ib thooj thiab tus lej nkag teb chaws txog 1 euro.

Xav tau ntawm chav kawm yog lub hwj chim xa tawm 3.3V ntawm ob peb puas milliamps. Tus tswj qhov hluav taws xob ntawm STM32F103C8 pawg thawj coj loj tsis siv, nws tsis tuaj yeem muab tam sim no txaus rau cov lus qhia. Cov ntaub ntawv rau MAX7219 hais qhia lub zog ua haujlwm yuav tsum nyob nruab nrab ntawm 4.0 thiab 5.5V tab sis nws ua haujlwm tau zoo ntawm 3.3V, tej zaum tsis yog thaum koj siv nws nyob hauv qhov kub lossis txias ib puag ncig, tab sis ntawm 20 Celsius nws zoo. Thiab tam sim no kuv tsis tas yuav siv qib-hloov pauv ntawm lub microcontroller thiab cov lus tso tawm.

Kauj ruam 2: Tsim

Tsim
Tsim
Tsim
Tsim
Tsim
Tsim

Thaum koj saib ntawm daim duab koj yuav pom tias kuv siv cov kab hluav taws xob ntawm lub khob cij hauv ib txoj hauv kev uas tsis yog ib txwm muaj, ob txoj kab saum toj kawg nkaus yog txoj kev tsheb nqaj hlau zoo thiab ob qho hauv qab yog txoj kev tsheb nqaj hlau. Nws yog txoj kev uas kuv tau siv los ua nws thiab nws ua haujlwm tau zoo, nws ua rau teeb tsa me ntsis ntxiv zoo li cov lej uas kuv kos. Tsis tas li, Kuv tau ua ntau daim txiag me me nrog ntu uas kuv tuaj yeem ntsaws rau hauv lub khob cij kom nrawm dua thiab lawv txhua tus tau teeb tsa los siv ob kab saum toj kawg nkaus raws li qhov zoo thiab kab qis dua hauv av. Raws li kuv tau hais, qhov kev daws teeb meem yog 4 ntsis (16 qib), thiab raws li muaj 4x8 leds ib sab ntawm ib leeg muaj tsuas yog 32 cov ntsiab lus piv txwv (pts). Sib piv qhov ntawd nrog Rigol Rigol DS1054Z (8 ntsis thiab 12Mpts) thiab koj yuav pom tias qhov no tsis yog khoom ua si. Dab tsi yog qhov bandwidth tiag, Kuv tsis paub, Kuv tau sim nws txog 10kHz thiab qhov ntawd ua haujlwm zoo.

Kauj Ruam 3: Cov khoos kas

Cov kev kawm
Cov kev kawm
Cov kev kawm
Cov kev kawm
Cov kev kawm
Cov kev kawm
Cov kev kawm
Cov kev kawm

IDE Kuv siv yog Atollic TrueStudio uas yog pib xyoo no (2018) tau txais los ntawm ST Micro Electronics thiab muaj pub dawb, tsis muaj sijhawm txwv, tsis muaj qhov txwv me me, tsis muaj nag-screens. Ua ke nrog nws, Kuv siv STM32CubeMX, ib txoj haujlwm uas muab rau kuv nrog cov lej pib thiab tsim qhov pib ntawm txhua qhov khoom siv. Thiab nws muaj cov zaub ntawm txhua tus pin ntawm microcontroller thiab lawv siv. Txawm hais tias koj tsis siv STM32CubeMX rau kev tsim cov cai, qhov no yooj yim heev. Ib yam uas kuv tsis nyiam yog hu ua HAL uas yog lub hauv paus ntawm STM32CubeMX. Kuv nyiam qhov txheej txheem LowLayer ntawm kev ua haujlwm.

Txhawm rau program microcontroller kuv siv ST-Txuas programmer/debugger los ntawm ST Micro Electronics lossis J-Link ua los ntawm Segger. Ob qho khoom siv no tsis pub dawb, txawm hais tias koj tuaj yeem yuav Suav cov ntawv luam ntawm lawv rau ob peb euros.

Kauj Ruam 4: Txog Txoj Cai

MAX7219 qhov chaw nyob LEDs qhov kuv hu ua kab rov tav, 8 leds nyob ib sab. Txog oscilloscope 8 LED's nyob rau ib sab yuav yooj yim dua, yog li kuv tau ua tus ncej yooj yim-tsis uas tau sau rau nrog cov ntaub ntawv hauv txoj kev ntsug, thiab nyeem tawm hauv txoj kev xav tau kab rov tav. MAX7219 siv 16 tus lej lej rau 8 LEDs, qhov twg thawj byte tau siv los hais txog kab uas tau xaiv. Thiab raws li muaj plaub ntawm cov qauv no tau teeb tsa ib sab ntawm ib leeg, nrog lawv cov tswv yim txuas nrog rau cov txiaj ntsig ntawm cov qauv ua ntej nws, koj yuav tsum xa cov 16bits plaub zaug kom mus txog qhov kawg. (Kuv vam tias kuv yuav ua kom pom tseeb…) Cov ntaub ntawv raug xa mus rau MAX7219 siv SPI, cov txheej txheem yooj yim tab sis nrawm heev. Nov yog qhov kuv tau sim nrog, koj tuaj yeem nrawm xa cov ntaub ntawv mus rau MAX7219. Thaum kawg, Kuv hloov rov qab mus rau 9 MHz tsuas yog qis tshaj qhov siab tshaj plaws uas cov ntawv teev tseg qhia meej.

Kuv siv ob ntawm plaub qhov muaj timers ntawm STM32F103C8, ib qho rau tiam ntawm lub sijhawm thiab lwm qhov rau nyeem tawm tus lej nkag teb chaws, uas teev lub sijhawm. TIMER3 tsim lub sijhawm ua haujlwm, nws ua nws los ntawm kev faib lub moos los ntawm 230, hloov kho lub txee txhua 3.2 uS. Dab ntxwg nyoog tus lej nkag teb chaws koj tuaj yeem xaiv kom muaj lub txee suav los ntawm 2 lub moos mem tes mus txog 2000 lub moos mem tes. Wb hais tias koj xaiv 100. TIMER3 tom qab ntawd tsim qhov xwm txheej txhua 320 uS. Qhov xwm txheej no ua rau ADC sau ib qho piv txwv ntawm cov teeb liab nkag mus, thiab zoo li yog 32 qhov piv txwv coj los rau ib qho tshuaj ntsuam, qhov no yuav ua tiav tom qab kwv yees. 10 mS os. Hauv 10mS koj tuaj yeem haum ib nthwv dej ntawm 100 Hz, lossis ob ntawm 200 Hz, thiab ntxiv rau. Mus hla 3 nthwv dej ntawm ib lub vijtsam ua rau nws nyuaj rau paub txog cov qauv nthwv dej txawm hais tias.

Txog qhov seem, kuv tsuas tuaj yeem xa koj mus rau txoj cai, nws tsis nyuaj ua raws txawm tias koj tsuas muaj qee qhov kev paub nrog Arduino. Qhov tseeb, koj tuaj yeem ua qhov qub nrog Arduino, txawm hais tias kuv tsis ntseeg tias nws yuav ua haujlwm nrawm dua li "ntsiav tshuaj xiav". STM32F103C8 yog 32 ntsis microcontroller khiav ntawm 72 MHz, nws muaj ob SPI cov khoom siv thiab ADC nrawm heev.

Kauj ruam 5: Main.h

#ifndef _MAIN_H _#txhais _MAIN_H_

#suav nrog "stm32f1xx_ll_adc.h"

#include "stm32f1xx_ll_rcc.h" #include "stm32f1xx_ll_bus.h" #include "stm32f1xx_ll_system.h" #include "stm32f1xx_ll_exti.h" #include "stm32f1xx_ll_system.h" #include "stm32f1xx_ll_exti.h" #include "stm32f1xx_ll_cortex.h" suav nrog "stm32f1xx_ll_dma.h" #include "stm32f1xx_ll_spi.h" #include "stm32f1xx_ll_tim.h" #include "stm32f1xx_ll_spi.h" #include "stm32f1xx_ll_tim.h" #include "stm32f1xx.h" #include "stm32f1xx_ll_gpio.h"

#ifndef NVIC_PRIORITYGROUP_0

#define NVIC_PRIORITYGROUP_0 ((uint32_t) 0x00000007) #define NVIC_PRIORITYGROUP_1 ((uint32_t) 0x00000006) #define NVIC_PRIORITYGROUP_2 ((uint32_t) 0x00000005) #define NVIC_PRIOR000 (0x00000000))

#ifdef _cplusplus

extern "C" {#endif void _Error_Handler (char *, int);

#define Error_Handler () _Error_Handler (_ FILE_, _LINE_)

#ifdef _cplusplus} #endif

#ib

Kauj Ruam 6: Main.c

#suav nrog "main.h" zoo li qub LL_Init (tsis muaj dab tsi); khoob khoob SystemClock_Config (tsis muaj dab tsi); zoo li qub tsis muaj dab tsi MX_GPIO_Init (tsis muaj dab tsi); zoo li qub tsis muaj nuj nqis MX_ADC1_Init (tsis muaj dab tsi); zoo li qub tsis muaj nuj nqis MX_SPI1_Init (tsis muaj dab tsi); zoo li qub tsis muaj nuj nqis MX_SPI2_Init (tsis muaj dab tsi); zoo li qub tsis muaj dab tsi MX_TIM3_Init (tsis muaj dab tsi); zoo li qub tsis muaj dab tsi MX_TIM4_Init (tsis muaj dab tsi);

uint16_t SPI1_send64 (uint16_t data3, uint16_t data2, uint16_t data1, uint16_t data0);

uint16_t SPI2_send64 (uint16_t data3, uint16_t data2, uint16_t data1, uint16_t data0); tsis muaj dab tsi MAX7219_1_init (); tsis muaj dab tsi MAX7219_2_init (); void erase_frame_buffer (tsis muaj dab tsi); tsis muaj dab tsi fill_frame_buffer (tsis muaj dab tsi); void display_frame_buffer (tsis muaj dab tsi); tsis muaj dab tsi set_timebase (tsis muaj dab tsi);

uint8_t upper_display [4] [8]; // vier bytes naast elkaar, acht onder elkaar

uint8_t lower_display [4] [8]; // deze twee samen vormen de thav duab-tsis

uint8_t sample_buffer [32]; // tsis voor de resultaten van de ADC

int main (tsis muaj dab tsi)

{LL_Init (); SystemClock_Config (); MX_GPIO_Init (); MX_ADC1_Init (); MX_SPI1_Init (); MX_SPI2_Init (); MX_TIM3_Init (); MX_TIM4_Init ();

LL_SPI_Enable (SPI1);

LL_SPI_Enable (SPI2);

LL_TIM_EnableCounter (TIM3);

LL_TIM_EnableCounter (TIM4);

LL_ADC_Enable (ADC1);

LL_ADC_REG_StartConversionSWStart (ADC1); LL_ADC_EnableIT_EOS (ADC1);

LL_mDelay (500); // MAX7219 xav tau qee lub sijhawm tom qab qhib lub zog

MAX7219_1_init (); MAX7219_2_init ();

// LL_TIM_SetAutoReload (TIM3, 9);

thaum (1)

{set_timebase (); lwv_frame_buffer (); fill_frame_buffer (); cov. display_frame_buffer (); }}

void erase_frame_buffer (tsis muaj dab tsi)

{int8_t x; int8_t tau;

rau (x = 0; x <4; x ++) // kolom_bytes {

rau (y = 0; y <8; y ++) // lijnen {upper_display [x] [y] = 0; // txhua qhov bitjes op nul lower_display [x] [y] = 0; }}}

void fill_frame_buffer (tsis muaj dab tsi)

{uint8_t y = 0; // voltage uint8_t tijd = 0; // tijd uint8_t display_byte; // steeds 8 khoom naast elkaar en dat 4 maal op een lijn uint8_t display_bit;

rau (tijd = 0; tijd <32; tijd ++) {display_byte = tijd / 8; display_bit = 7 - (tijd % 8);

y = sample_buffer [tijd];

yog (y> 7) // nyob rau sab sauv zaub schrijven

{upper_display [display_byte] [15-y] | = (1 << display_bit); } lwm yam // hauv qis zaub schrijven {lower_display [display_byte] [7-y] | = (1 << display_bit); }}}

void display_frame_buffer (tsis muaj dab tsi)

{

uint8_t y; // acht lijnen boven elkaar (ib qho zaub) uint16_t yl; // lijnnummer voor de MAX7219

rau (y = 0; y <8; y ++) {yl = (y+1) << 8; // MAX7219 heeft lijnnummer in de upper 8 bits van 16 bits woord

SPI2_send64 ((yl | upper_display [0] [y]), (yl | upper_display [1] [y]), (yl | upper_display [2] [y]), (yl | upper_display [3] [y]));

SPI1_send64 ((yl | lower_display [0] [y]), (yl | lower_display [1] [y]), (yl | lower_display [2] [y]), (yl | lower_display [3] [y])); }

}

void set_timebase (tsis muaj dab tsi)

{uint8_t timebase_knop;

timebase_knop = LL_TIM_GetCounter (TIM4) / 2;

hloov (timebase_knop)

{rooj plaub 0: LL_TIM_SetAutoReload (TIM3, 1999); tawg; rooj plaub 1: LL_TIM_SetAutoReload (TIM3, 999); tawg; rooj plaub 2: LL_TIM_SetAutoReload (TIM3, 499); tawg; rooj plaub 3: LL_TIM_SetAutoReload (TIM3, 199); tawg; rooj plaub 4: LL_TIM_SetAutoReload (TIM3, 99); tawg; rooj plaub 5: LL_TIM_SetAutoReload (TIM3, 49); tawg; rooj plaub 6: LL_TIM_SetAutoReload (TIM3, 19); tawg; rooj plaub 7: LL_TIM_SetAutoReload (TIM3, 9); tawg; rooj plaub 8: LL_TIM_SetAutoReload (TIM3, 4); tawg; rooj plaub 9: LL_TIM_SetAutoReload (TIM3, 1); tawg;

neej ntawd hais:

LL_TIM_SetAutoReload (TIM3, 99); tawg; }}

tsis muaj dab tsi MAX7219_1_init ()

{SPI1_send64 (0x0000, 0x0000, 0x0000, 0x0000); // nop SPI1_send64 (0x0C00, 0x0C00, 0x0C00, 0x0C00); // kaw ntawm SPI1_send64 (0x0000, 0x0000, 0x0000, 0x0000); // nop SPI1_send64 (0x0F00, 0x0F00, 0x0F00, 0x0F00); // testmode tawm SPI1_send64 (0x0C01, 0x0C01, 0x0C01, 0x0C01); // kaw, kev ua haujlwm ib txwm SPI1_send64 (0x0900, 0x0900, 0x0900, 0x0900); // tsis muaj 7seg txiav txim, 64 pixels SPI1_send64 (0x0A07, 0x0A07, 0x0A07, 0x0A07); // siv 50% SPI1_send64 (0x0B07, 0x0B07, 0x0B07, 0x0B07); // txhua kab ntawm}

tsis muaj dab tsi MAX7219_2_init ()

{SPI2_send64 (0x0000, 0x0000, 0x0000, 0x0000); // nop SPI2_send64 (0x0C00, 0x0C00, 0x0C00, 0x0C00); // kaw ntawm SPI2_send64 (0x0000, 0x0000, 0x0000, 0x0000); // nop SPI2_send64 (0x0F00, 0x0F00, 0x0F00, 0x0F00); // testmode tawm SPI2_send64 (0x0C01, 0x0C01, 0x0C01, 0x0C01); // kaw, kev ua haujlwm ib txwm SPI2_send64 (0x0900, 0x0900, 0x0900, 0x0900); // tsis muaj 7seg txiav txim, 64 pixels SPI2_send64 (0x0A07, 0x0A07, 0x0A07, 0x0A07); // siv 50% SPI2_send64 (0x0B07, 0x0B07, 0x0B07, 0x0B07); // txhua kab ntawm}

uint16_t SPI1_send64 (uint16_t data3, uint16_t data2, uint16_t data1, uint16_t data0)

{LL_GPIO_ResetOutputPin (GPIOA, LL_GPIO_PIN_4);

LL_SPI_TransmitData16 (SPI1, data3);

thaum (LL_SPI_IsActiveFlag_TXE (SPI1) == 0) {}

LL_SPI_TransmitData16 (SPI1, data2);

thaum (LL_SPI_IsActiveFlag_TXE (SPI1) == 0) {}

LL_SPI_TransmitData16 (SPI1, data1);

thaum (LL_SPI_IsActiveFlag_TXE (SPI1) == 0) {}

LL_SPI_TransmitData16 (SPI1, data0);

thaum (LL_SPI_IsActiveFlag_BSY (SPI1) == 1) {}

LL_GPIO_SetOutputPin (GPIOA, LL_GPIO_PIN_4);

rov qab LL_SPI_ReceiveData16 (SPI1); }

uint16_t SPI2_send64 (uint16_t data3, uint16_t data2, uint16_t data1, uint16_t data0)

{LL_GPIO_ResetOutputPin (GPIOB, LL_GPIO_PIN_12);

LL_SPI_TransmitData16 (SPI2, data3);

thaum (LL_SPI_IsActiveFlag_TXE (SPI2) == 0) {}

LL_SPI_TransmitData16 (SPI2, data2);

thaum (LL_SPI_IsActiveFlag_TXE (SPI2) == 0) {}

LL_SPI_TransmitData16 (SPI2, data1);

thaum (LL_SPI_IsActiveFlag_TXE (SPI2) == 0) {}

LL_SPI_TransmitData16 (SPI2, data0);

thaum (LL_SPI_IsActiveFlag_BSY (SPI2) == 1) {}

LL_GPIO_SetOutputPin (GPIOB, LL_GPIO_PIN_12);

rov LL_SPI_ReceiveData16 (SPI2); }

void ADC1_2_IRQHandler (tsis muaj dab tsi)

{zoo li qub uint8_t sample_counter; uint8_t txhais; zoo li qub uint8_t yav dhau los_trigger;

yog (LL_ADC_IsActiveFlag_EOS (ADC1)! = RESET)

{yog (sample_counter <32) {sample_buffer [sample_counter] = LL_ADC_REG_ReadConversionData32 (ADC1) / 256; yog (sample_counter <32) sample_counter ++; lwm tus qauv_counter = 0; } lwm tus {txhais = LL_ADC_REG_ReadConversionData32 (ADC1) / 256;

if ((trigger == 7) && (previous_trigger <trigger)) // gaat niet helemaal goed bij blokgolven… {sample_counter = 0; } yav dhau los_trigger = txhais; }

LL_GPIO_TogglePin (GPIOC, LL_GPIO_PIN_13);

LL_ADC_ClearFlag_EOS (ADC1);

} }

LL_Init (zoo li qub)

{LL_APB2_GRP1_EnableClock (LL_APB2_GRP1_PERIPH_AFIO); LL_APB1_GRP1_EnableClock (LL_APB1_GRP1_PERIPH_PWR);

NVIC_SetPriorityGrouping (NVIC_PRIORITYGROUP_4);

NVIC_SetPriority (MemoryManagement_IRQn, NVIC_EncodePriority (NVIC_GetPriorityGrouping (), 0, 0))); NVIC_SetPriority (BusFault_IRQn, NVIC_EncodePriority (NVIC_GetPriorityGrouping (), 0, 0))); NVIC_SetPriority (UsageFault_IRQn, NVIC_EncodePriority (NVIC_GetPriorityGrouping (), 0, 0))); NVIC_SetPriority (SVCall_IRQn, NVIC_EncodePriority (NVIC_GetPriorityGrouping (), 0, 0))); NVIC_SetPriority (DebugMonitor_IRQn, NVIC_EncodePriority (NVIC_GetPriorityGrouping (), 0, 0))); NVIC_SetPriority (PendSV_IRQn, NVIC_EncodePriority (NVIC_GetPriorityGrouping (), 0, 0))); NVIC_SetPriority (SysTick_IRQn, NVIC_EncodePriority (NVIC_GetPriorityGrouping (), 0, 0)));

LL_GPIO_AF_Remap_SWJ_NOJTAG ();

}

void SystemClock_Config (tsis muaj dab tsi)

{LL_FLASH_SetLatency (LL_FLASH_LATENCY_2); yog (LL_FLASH_GetLatency ()! = LL_FLASH_LATENCY_2) Error_Handler (); LL_RCC_HSE_Enable (); thaum (LL_RCC_HSE_IsReady ()! = 1); LL_RCC_PLL_ConfigDomain_SYS (LL_RCC_PLLSOURCE_HSE_DIV_1, LL_RCC_PLL_MUL_9); LL_RCC_PLL_Enable (); thaum (LL_RCC_PLL_IsReady ()! = 1); LL_RCC_SetAHBPrescaler (LL_RCC_SYSCLK_DIV_1); LL_RCC_SetAPB1Prescaler (LL_RCC_APB1_DIV_2); LL_RCC_SetAPB2Prescaler (LL_RCC_APB2_DIV_1); LL_RCC_SetSysClkSource (LL_RCC_SYS_CLKSOURCE_PLL); thaum (LL_RCC_GetSysClkSource ()! = LL_RCC_SYS_CLKSOURCE_STATUS_PLL); LL_Init1msTick (72000000); LL_SYSTICK_SetClkSource (LL_SYSTICK_CLKSOURCE_HCLK); LL_SetSystemCoreClock (72000000); LL_RCC_SetADCClockSource (LL_RCC_ADC_CLKSRC_PCLK2_DIV_6);

NVIC_SetPriority (SysTick_IRQn, NVIC_EncodePriority (NVIC_GetPriorityGrouping (), 0, 0)));

}

zoo li qub tsis muaj nuj nqis MX_ADC1_Init (tsis muaj dab tsi)

{LL_ADC_InitTypeDef ADC_InitStruct; LL_ADC_CommonInitTypeDef ADC_CommonInitStruct; LL_ADC_REG_InitTypeDef ADC_REG_InitStruct; LL_GPIO_InitTypeDef GPIO_InitStruct;

LL_APB2_GRP1_EnableClock (LL_APB2_GRP1_PERIPH_ADC1);

GPIO_InitStruct. Pin = LL_GPIO_PIN_0;

GPIO_InitStruct. Mode = LL_GPIO_MODE_ANALOG; LL_GPIO_Init (GPIOA, & GPIO_InitStruct);

NVIC_SetPriority (ADC1_2_IRQn, NVIC_EncodePriority (NVIC_GetPriorityGrouping (), 0, 0)));

NVIC_EnableIRQ (ADC1_2_IRQn);

ADC_InitStruct. DataAlignment = LL_ADC_DATA_ALIGN_RIGHT;

ADC_InitStruct. SequencersScanMode = LL_ADC_SEQ_SCAN_DISABLE; LL_ADC_Init (ADC1, & ADC_InitStruct);

ADC_CommonInitStruct. Multimode = LL_ADC_MULTI_INDEPENDENT;

LL_ADC_CommonInit (_ LL_ADC_COMMON_INSTANCE (ADC1), & ADC_CommonInitStruct);

ADC_REG_InitStruct. TriggerSource = LL_ADC_REG_TRIG_EXT_TIM3_TRGO;

ADC_REG_InitStruct. SequencerLength = 1; ADC_REG_InitStruct. SequencerDiscont = LL_ADC_REG_SEQ_DISCONT_DISABLE; ADC_REG_InitStruct. ContinuousMode = LL_ADC_REG_CONV_SINGLE; ADC_REG_InitStruct. DMATransfer = LL_ADC_REG_DMA_TRANSFER_NONE; LL_ADC_REG_Init (ADC1, & ADC_REG_InitStruct);

LL_ADC_SetChannelSamplingTime (ADC1, LL_ADC_CHANNEL_0, LL_ADC_SAMPLINGTIME_41CYCLES_5);

}

zoo li qub tsis muaj nuj nqis MX_SPI1_Init (tsis muaj dab tsi)

{LL_SPI_InitTypeDef SPI_InitStruct; LL_GPIO_InitTypeDef GPIO_InitStruct;

LL_APB2_GRP1_EnableClock (LL_APB2_GRP1_PERIPH_SPI1);

GPIO_InitStruct. Pin = LL_GPIO_PIN_5 | LL_GPIO_PIN_7;

GPIO_InitStruct. Mode = LL_GPIO_MODE_ALTERNATE; GPIO_InitStruct. Speed = LL_GPIO_SPEED_FREQ_HIGH; GPIO_InitStruct. OutputType = LL_GPIO_OUTPUT_PUSHPULL; LL_GPIO_Init (GPIOA, & GPIO_InitStruct);

// NVIC_SetPriority (SPI1_IRQn, NVIC_EncodePriority (NVIC_GetPriorityGrouping (), 0, 0)));

// NVIC_EnableIRQ (SPI1_IRQn);

SPI_InitStruct. TransferDirection = LL_SPI_FULL_DUPLEX;

SPI_InitStruct. Mode = LL_SPI_MODE_MASTER; SPI_InitStruct. DataWidth = LL_SPI_DATAWIDTH_16BIT; SPI_InitStruct. ClockPolarity = LL_SPI_POLARITY_LOW; SPI_InitStruct. ClockPhase = LL_SPI_PHASE_1EDGE; SPI_InitStruct. NSS = LL_SPI_NSS_SOFT; SPI_InitStruct. BaudRate = LL_SPI_BAUDRATEPRESCALER_DIV8; SPI_InitStruct. BitOrder = LL_SPI_MSB_FIRST; SPI_InitStruct. CRCCalculation = LL_SPI_CRCCALCULATION_DISABLE; SPI_InitStruct. CRCPoly = 10; LL_SPI_Init (SPI1, & SPI_InitStruct); }

zoo li qub tsis muaj nuj nqis MX_SPI2_Init (tsis muaj dab tsi)

{LL_SPI_InitTypeDef SPI_InitStruct; LL_GPIO_InitTypeDef GPIO_InitStruct;

LL_APB1_GRP1_EnableClock (LL_APB1_GRP1_PERIPH_SPI2);

GPIO_InitStruct. Pin = LL_GPIO_PIN_13 | LL_GPIO_PIN_15;

GPIO_InitStruct. Mode = LL_GPIO_MODE_ALTERNATE; GPIO_InitStruct. Speed = LL_GPIO_SPEED_FREQ_HIGH; GPIO_InitStruct. OutputType = LL_GPIO_OUTPUT_PUSHPULL; LL_GPIO_Init (GPIOB, & GPIO_InitStruct);

// NVIC_SetPriority (SPI2_IRQn, NVIC_EncodePriority (NVIC_GetPriorityGrouping (), 0, 0)));

// NVIC_EnableIRQ (SPI2_IRQn);

SPI_InitStruct. TransferDirection = LL_SPI_FULL_DUPLEX;

SPI_InitStruct. Mode = LL_SPI_MODE_MASTER; SPI_InitStruct. DataWidth = LL_SPI_DATAWIDTH_16BIT; SPI_InitStruct. ClockPolarity = LL_SPI_POLARITY_LOW; SPI_InitStruct. ClockPhase = LL_SPI_PHASE_1EDGE; SPI_InitStruct. NSS = LL_SPI_NSS_SOFT; SPI_InitStruct. BaudRate = LL_SPI_BAUDRATEPRESCALER_DIV4; SPI_InitStruct. BitOrder = LL_SPI_MSB_FIRST; SPI_InitStruct. CRCCalculation = LL_SPI_CRCCALCULATION_DISABLE; SPI_InitStruct. CRCPoly = 10; LL_SPI_Init (SPI2, & SPI_InitStruct); }

zoo li qub tsis muaj dab tsi MX_TIM3_Init (tsis muaj dab tsi)

{LL_TIM_InitTypeDef TIM_InitStruct;

LL_APB1_GRP1_EnableClock (LL_APB1_GRP1_PERIPH_TIM3);

TIM_InitStruct. Prescaler = 229;

TIM_InitStruct. CounterMode = LL_TIM_COUNTERMODE_UP; TIM_InitStruct. Autoreload = 9; TIM_InitStruct. ClockDivision = LL_TIM_CLOCKDIVISION_DIV1; LL_TIM_Init (TIM3, & TIM_InitStruct);

LL_TIM_DisableARRPreload (TIM3);

LL_TIM_SetClockSource (TIM3, LL_TIM_CLOCKSOURCE_INTERNAL); LL_TIM_SetTriggerOutput (TIM3, LL_TIM_TRGO_UPDATE); LL_TIM_EnableMasterSlaveMode (TIM3); }

zoo li qub tsis muaj dab tsi MX_TIM4_Init (tsis muaj dab tsi)

{LL_TIM_InitTypeDef TIM_InitStruct; LL_GPIO_InitTypeDef GPIO_InitStruct;

LL_APB1_GRP1_EnableClock (LL_APB1_GRP1_PERIPH_TIM4);

GPIO_InitStruct. Pin = LL_GPIO_PIN_6 | LL_GPIO_PIN_7;

GPIO_InitStruct. Mode = LL_GPIO_MODE_FLOATING; LL_GPIO_Init (GPIOB, & GPIO_InitStruct);

LL_TIM_SetEncoderMode (TIM4, LL_TIM_ENCODERMODE_X2_TI1);

LL_TIM_IC_SetActiveInput (TIM4, LL_TIM_CHANNEL_CH1, LL_TIM_ACTIVEINPUT_DIRECTTI); LL_TIM_IC_SetPrescaler (TIM4, LL_TIM_CHANNEL_CH1, LL_TIM_ICPSC_DIV1); LL_TIM_IC_SetFilter (TIM4, LL_TIM_CHANNEL_CH1, LL_TIM_IC_FILTER_FDIV1); LL_TIM_IC_SetPolarity (TIM4, LL_TIM_CHANNEL_CH1, LL_TIM_IC_POLARITY_RISING); LL_TIM_IC_SetActiveInput (TIM4, LL_TIM_CHANNEL_CH2, LL_TIM_ACTIVEINPUT_DIRECTTI); LL_TIM_IC_SetPrescaler (TIM4, LL_TIM_CHANNEL_CH2, LL_TIM_ICPSC_DIV1); LL_TIM_IC_SetFilter (TIM4, LL_TIM_CHANNEL_CH2, LL_TIM_IC_FILTER_FDIV1); LL_TIM_IC_SetPolarity (TIM4, LL_TIM_CHANNEL_CH2, LL_TIM_IC_POLARITY_RISING);

TIM_InitStruct. Prescaler = 0;

TIM_InitStruct. CounterMode = LL_TIM_COUNTERMODE_UP; TIM_InitStruct. Autoreload = 19; TIM_InitStruct. ClockDivision = LL_TIM_CLOCKDIVISION_DIV1; LL_TIM_Init (TIM4, & TIM_InitStruct);

LL_TIM_DisableARRPreload (TIM4);

LL_TIM_SetTriggerOutput (TIM4, LL_TIM_TRGO_RESET); LL_TIM_DisableMasterSlaveMode (TIM4); }

zoo li qub tsis muaj dab tsi MX_GPIO_Init (tsis muaj dab tsi)

{LL_GPIO_InitTypeDef GPIO_InitStruct;

LL_APB2_GRP1_EnableClock (LL_APB2_GRP1_PERIPH_GPIOC);

LL_APB2_GRP1_EnableClock (LL_APB2_GRP1_PERIPH_GPIOD); LL_APB2_GRP1_EnableClock (LL_APB2_GRP1_PERIPH_GPIOA); LL_APB2_GRP1_EnableClock (LL_APB2_GRP1_PERIPH_GPIOB);

LL_GPIO_SetOutputPin (GPIOC, LL_GPIO_PIN_13);

LL_GPIO_SetOutputPin (GPIOA, LL_GPIO_PIN_4); LL_GPIO_SetOutputPin (GPIOB, LL_GPIO_PIN_12);

GPIO_InitStruct. Pin = LL_GPIO_PIN_13;

GPIO_InitStruct. Mode = LL_GPIO_MODE_OUTPUT; GPIO_InitStruct. Speed = LL_GPIO_SPEED_FREQ_LOW; GPIO_InitStruct. OutputType = LL_GPIO_OUTPUT_PUSHPULL; LL_GPIO_Init (GPIOC, & GPIO_InitStruct);

GPIO_InitStruct. Pin = LL_GPIO_PIN_4;

GPIO_InitStruct. Mode = LL_GPIO_MODE_OUTPUT; GPIO_InitStruct. Speed = LL_GPIO_SPEED_FREQ_HIGH; GPIO_InitStruct. OutputType = LL_GPIO_OUTPUT_PUSHPULL; LL_GPIO_Init (GPIOA, & GPIO_InitStruct);

GPIO_InitStruct. Pin = LL_GPIO_PIN_12;

GPIO_InitStruct. Mode = LL_GPIO_MODE_OUTPUT; GPIO_InitStruct. Speed = LL_GPIO_SPEED_FREQ_HIGH; GPIO_InitStruct. OutputType = LL_GPIO_OUTPUT_PUSHPULL; LL_GPIO_Init (GPIOB, & GPIO_InitStruct); }

void _Error_Handler (char *file, int kab)

{thaum (1) {}}

#ifdef USE_FULL_ASSERT

void assert_failed (uint8_t* file, uint32_t kab)

{} #endif

Pom zoo: