Thiết kế máy phát tần số sử dụng PWM từ 1Hz 1000Hz và hiển thị giá trị lên 4 con led 7 thanh.

11 31 0
Thiết kế máy phát tần số sử dụng PWM từ 1Hz  1000Hz và hiển thị giá trị lên 4 con led 7 thanh.

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

HỌC VIỆN CƠNG NGHỆ BƯU CHÍNH VIỄN THƠNG  BÁO CÁO BÀI TẬP LỚN Môn học: HỆ THỐNG NHÚNG Giảng viên hướng dẫn : Nguyễn Ngọc Minh Nhóm : 14 Sinh viên thực :Nguyễn Đức Hiệp-B18DCDT071 Nguyễn Văn Cường-B18DCDT022 Lê Ngọc Sơn-B18DCDT204 Nguyễn Kính Đảm-B18DCDT039 Hà Nội - - Thiết kế máy phát tần số sử dụng PWM từ 1Hz - 1000Hz hiển thị giá trị lên led 1.Tổng quan - Máy cho tần số đầu từ 1Hz đến 1000Hz, độ rộng xung từ 0% đến 100% - Tần số đầu hiển thị lên LED đoạn - Tần số Clock đầu vào sử dụng 8MHz - Hạn chế: Muốn thay đổi tần số phát độ rộng xung, ta phải khai báo lại code phần define - Máy mô phần mềm Proteus Code #include #include #include #include "stm32f10x.h" // Device header "stm32f10x_rcc.h" // Keil::Device:StdPeriph Drivers:RCC "stm32f10x_gpio.h" // Keil::Device:StdPeriph Drivers:GPIO "stm32f10x_tim.h" // Keil::Device:StdPeriph Drivers:TIM GPIO_InitTypeDef GPIO_InitStructure; TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; TIM_OCInitTypeDef TIM_OCInitStructure; #define #define #define #define #define #define #define LED7SEG_A LED7SEG_B LED7SEG_C LED7SEG_D LED7SEG_E LED7SEG_F LED7SEG_G GPIO_Pin_0 GPIO_Pin_1 GPIO_Pin_2 GPIO_Pin_3 GPIO_Pin_4 GPIO_Pin_5 GPIO_Pin_6 #define LED7SEG_DP GPIO_Pin_7 #define #define #define #define LED1 LED2 LED3 LED4 GPIO_Pin_1 GPIO_Pin_2 GPIO_Pin_3 GPIO_Pin_4 #define PORT_LED7SEG_CODE GPIOC #define PORT_LED GPIOB #define PORT_LED7SEG_CODE_CLOCK RCC_APB2Periph_GPIOC #define PORT_LED_CLOCK RCC_APB2Periph_GPIOB #define F (100) #define PW (0.66) uint16_t LED7SEG[10]={0xC0, 0xF9, 0xA4, 0xB0, 0x99, 0x92, 0x82, 0xF8, 0x80, 0x90}; void TIM_PWM_Configuration(void); void GPIO_Config(void); void Delay(uint32_t); int main (void){ SystemInit(); SystemCoreClockUpdate(); GPIO_Config(); TIM_PWM_Configuration(); //TIM1->CCR1 = 50 * ((10000/F) / 100); //50% Duty cycle GPIO_ResetBits(PORT_LED, LED1); //LED1 = 0; GPIO_ResetBits(PORT_LED, LED2); //LED2 = 0; GPIO_ResetBits(PORT_LED, LED3); //LED1 = 0; GPIO_ResetBits(PORT_LED, LED4); //LED2 = 0; while(1) { for(uint8_t j = 0; j < 30; j++) { GPIO_ResetBits(PORT_LED, LED2); GPIO_ResetBits(PORT_LED, LED3); GPIO_ResetBits(PORT_LED, LED4); GPIO_Write(PORT_LED7SEG_CODE, LED7SEG[F/1000]); GPIO_SetBits(PORT_LED, LED1); Delay(1); GPIO_ResetBits(PORT_LED, LED1); GPIO_ResetBits(PORT_LED, LED3); GPIO_ResetBits(PORT_LED, LED4); GPIO_Write(PORT_LED7SEG_CODE, LED7SEG[(F %1000)/100]); GPIO_SetBits(PORT_LED, LED2); Delay(1); %1000%100)/10]); GPIO_ResetBits(PORT_LED, LED1); GPIO_ResetBits(PORT_LED, LED2); GPIO_ResetBits(PORT_LED, LED4); GPIO_Write(PORT_LED7SEG_CODE, LED7SEG[(F GPIO_SetBits(PORT_LED, LED3); Delay(1); %1000%100%10]); GPIO_ResetBits(PORT_LED, LED1); GPIO_ResetBits(PORT_LED, LED2); GPIO_ResetBits(PORT_LED, LED3); GPIO_Write(PORT_LED7SEG_CODE, LED7SEG[F GPIO_SetBits(PORT_LED, LED4); Delay(1); } } } void Delay(uint32_t t) { unsigned int i,j; for(i=0;i T = 1s + F = 10 PW = 0.25 => T = 100 ms = 0.1s + F = 100 PW = 0.66 => T = 10 ms = 0.01s + F = 1000 PW = 0.75 => T = ms = 0.001s + F = 222 PW = 0.22 => T = 4.45 ms = 0.00445s 10 11 .. .Thiết kế máy phát tần số sử dụng PWM từ 1Hz - 1000Hz hiển thị giá trị lên led 1.Tổng quan - Máy cho tần số đầu từ 1Hz đến 1000Hz, độ rộng xung từ 0% đến 100% - Tần số đầu hiển thị lên LED. .. GPIO_InitStructure.GPIO_Pin = LED7 SEG_A |LED7 SEG_B |LED7 SEG_C| LED7 SEG_D |LED7 SEG_E |LED7 SEG_F |LED7 SEG_G |LED7 SEG_A| LED7 SEG_DP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz; GPIO_Init(PORT _LED7 SEG_CODE, &GPIO_InitStructure);... #define LED7 SEG_A LED7 SEG_B LED7 SEG_C LED7 SEG_D LED7 SEG_E LED7 SEG_F LED7 SEG_G GPIO_Pin_0 GPIO_Pin_1 GPIO_Pin_2 GPIO_Pin_3 GPIO_Pin _4 GPIO_Pin_5 GPIO_Pin_6 #define LED7 SEG_DP GPIO_Pin _7 #define

Ngày đăng: 07/02/2022, 15:47

Tài liệu cùng người dùng

Tài liệu liên quan