-
LKS32MC08x系列时钟主频、机器周期、总线周期、指令周期计算 sos
1.在pll开启且不分频的条件下,用一个io口翻转电平的方式,在主循环内测试了一下输出频率,主循环内就一句代码:“GPIO0->PDO = ~GPIO0->PDO;”。得到的输出频率大概是2mhz,和预期值相差较大,所以询问一下如题。 2。以pwm方式触发ADC中断,在ADC中断中加入翻转gpio的测试。但是降低/提高pwm的频率对ADC中断中的电平翻转频率似乎没有影响?部分代码如下: void ADC0_init(void) { ADC_InitTypeDef ADC_InitStructure; ADC_StructInit(&ADC_InitStructure); //初始化结构体 ADC_InitStructure.IE = ADC_EOS0_IRQ_EN | ADC_DAT0_OV_IRQ_EN; //第一段扫描结束中断使能和ADC_DAT0超阈值中断 ADC_InitStructure.Align = ADC_LEFT_ALIGN; //ADC数据输出左对齐 ADC_InitStructure.UTIMER_Trigger_En = DISABLE; //UTIMER_T0硬件触发ADC采样 ADC_InitStructure.MCPWM_Trigger_En = ADC_MCPWM_T0_TRG; ADC_InitStructure.FirSeg_Ch = ADC_2_TIMES_SAMPLE; //第一段采样的总通道数: 1~20 ADC_InitStructure.Trigger_Cnt = 0; /*单段触发模式下触发一次采样所需要的事件数:0~15 0表示需要一次触发,15表示需要16次*///修改此处似乎进入中断的频率并没有更改? ADC_InitStructure.Trigger_Mode = ADC_1SEG_TRG; /*ADC采样1段模式*/ ADC_InitStructure.DAT0_TH_Type = ENABLE; //设置ADC比较上阈值中断使能 ADC0_DAT0_TH = 5000; //设置ADC0_DARA0大于ADC0_DAT0_TH值时,触发ADC数值比较中断 ADC_Init(ADC0, &ADC_InitStructure); ADC0_IF = 0xff; //清中断标志位 ADC0_GAIN0 = 0x0; //开启2/3增益 ADC0_CHN0 = ADC_CHANNEL_7 | (ADC_CHANNEL_16 << 8); //采样通道通道 } void MCPWM_init(void) { MCPWM_InitTypeDef MCPWM_InitStructure; MCPWM_StructInit(&MCPWM_InitStructure); MCPWM_InitStructure.CLK_DIV = PWM_PRSC; /* MCPWM时钟分频设置 */ MCPWM_InitStructure.MCLK_EN = ENABLE; /* 模块时钟开启 */ MCPWM_InitStructure.MCPWM_Cnt_EN = ENABLE; /* 主计数器开始计数使能开关 */ MCPWM_InitStructure.MCPWM_WorkModeCH0 = CENTRAL_PWM_MODE; /* MCPWM CH0工作模式:边沿对齐PWM模式 */ MCPWM_InitStructure.GPIO_BKIN_Filter = 0; /* 急停事件(来自IO口信号)数字滤波器时间设置 */ MCPWM_InitStructure.CMP_BKIN_Filter = 0; /* 急停事件(来自比较器信号)数字滤波器时间设置 */ MCPWM_InitStructure.MCPWM_PERIOD = PWM_PERIOD; /* 计数周期设置即MCPWM输出周期*/ MCPWM_InitStructure.TriggerPoint0 = (u16)(-PWM_PERIOD); /* MCPWM_TMR0 ADC触发事件T0 设置 */ 。。。 } void ADC0_IRQHandler(void) { if (ADC0_IF & BIT0) //判断是否发生第一采样完成中断 { ADC0_IF = BIT0; //清除第一段采样完成中断标志位 } if (ADC0_IF & BIT6) { ADC0_IF = BIT6; //清除ADC0_DAT0超阈值中断 } GPIO0->PDO = ~GPIO0->PDO; }
1621浏览量 0回复量 关注量 -
stm32U575 arduino进不了中断 sos
最近在学习arduino驱动STM32U575,开发环境为vs code platformio。freertos。我在使用检测IO是可以的,但是用中断,进不了中断。代码如下:[backcolor=rgb(255, 255, 255)][font=Menlo, Monaco, "][size=12px][color=#0000ff]#include [/color][color=#a31515]
[/color] [color=#0000ff]#include [/color][color=#a31515] [/color] [color=#0000ff]volatile[/color] [color=#0000ff]bool[/color] btnPressed = [color=#0000ff]true[/color]; [color=#0000ff]volatile[/color] [color=#0000ff]bool[/color] btnReleased = [color=#0000ff]false[/color]; [color=#0000ff]volatile[/color] [color=#0000ff]int[/color] couter = [color=#098658]0[/color]; SemaphoreHandle_t xSemaLED = [color=#0000ff]NULL[/color];[color=#008000] //创建信号量Handler[/color] [color=#0000ff]volatile[/color] TickType_t btnDeounce = [color=#098658]0[/color];[color=#008000] //用于button Debounce[/color] TickType_t timeOut = [color=#098658]1000[/color];[color=#008000] //用于获取信号量的TimeOut 1000ticks[/color] byte pin = [color=#0000ff]PB7[/color]; [color=#0000ff]void[/color] flashLED([color=#0000ff]void[/color] [color=#0000ff]*[/color] pt) { pinMode(pin,[color=#0000ff]OUTPUT[/color]); [color=#0000ff]while[/color]([color=#098658]1[/color]) { [color=#0000ff]if[/color]([color=#0000ff]xSemaphoreTake[/color](xSemaLED, timeOut) == [color=#0000ff]pdTRUE[/color]) { [color=#0000ff]if[/color]((xTaskGetTickCount() - btnDeounce) < [color=#098658]100[/color]){ digitalWrite(pin, !digitalRead(pin)); vTaskDelay([color=#098658]1000[/color]); } } } } [color=#0000ff]void[/color] buttonPressed() { [color=#0000ff]Serial[/color].println([color=#a31515]"but clicked."[/color]); btnDeounce = xTaskGetTickCountFromISR(); [color=#0000ff]xSemaphoreGiveFromISR[/color](xSemaLED, [color=#0000ff]NULL[/color]); } [color=#0000ff]void[/color] setup() { [color=#0000ff]Serial[/color].begin([color=#098658]115200[/color]); [color=#0000ff]Serial[/color].println([color=#a31515]"Start flash led...."[/color]); xSemaLED = [color=#0000ff]xSemaphoreCreateBinary[/color](); [color=#0000ff]if[/color] ( xSemaLED == [color=#0000ff]NULL[/color]){ [color=#0000ff]Serial[/color].println([color=#a31515]"No Enough Ram, Unable to Create Semaphore."[/color]); }[color=#0000ff]else[/color]{ xTaskCreate(flashLED, [color=#a31515]"Flash LED"[/color], [color=#098658]1024[/color], [color=#0000ff]NULL[/color], [color=#098658]6[/color], [color=#0000ff]NULL[/color]); } pinMode([color=#0000ff]PC13[/color], [color=#0000ff]INPUT_PULLDOWN[/color]); attachInterrupt([color=#0000ff]PC13[/color],buttonPressed,[color=#0000ff]HIGH[/color]);[color=#008000]// 创建外部中断[/color] } [color=#0000ff]void[/color] loop() { [color=#008000] // put your main code here, to run repeatedly:[/color] } [/size][/font][/backcolor] 2505浏览量 0回复量 关注量 -
CH573F IO 中断怎么用,是不是漏了什么配置, 一直不进中断
[color=rgb(249, 38, 114)][font=consolas, monospace]void gpio_wake_init() {[/font][/color] [font=consolas, monospace][color=#f92672] //初始化位输入上拉[/color][/font] [font=consolas, monospace][color=#f92672] GPIOB_ModeCfg(GPIO_Pin_4, GPIO_ModeIN_PU);[/color][/font] [font=consolas, monospace][color=#f92672] //开启下降沿中断[/color][/font] [font=consolas, monospace][color=#f92672] GPIOB_ITModeCfg(GPIO_Pin_4,GPIO_ITMode_FallEdge);[/color][/font] [font=consolas, monospace][color=#f92672] //开启GPIO睡眠唤醒[/color][/font] [font=consolas, monospace][color=#f92672] PWR_PeriphWakeUpCfg( ENABLE, RB_SLP_GPIO_WAKE,Edge_LongDelay );[/color][/font] [font=consolas, monospace][color=#f92672] //开启GPIOB中断[/color][/font] [font=consolas, monospace][color=#f92672] PFIC_EnableIRQ(GPIO_B_IRQn);[/color][/font] [font=consolas, monospace][color=#f92672]}[/color][/font] [font=consolas, monospace][color=#f92672] [/color][/font] [font=consolas, monospace][color=#f92672]//中断服务程序[/color][/font] [font=consolas, monospace][color=#f92672]__attribute__((interrupt("WCH-Interrupt-fast"))) //硬件压栈[/color][/font] [font=consolas, monospace][color=#f92672]__attribute__((section(".highcode"))) //放到RAM里[/color][/font] [font=consolas, monospace][color=#f92672]void GPIOB_IRQHandler(void) {[/color][/font] [font=consolas, monospace][color=#f92672] PRINT("gpio interrupt\r\n");[/color][/font] [font=consolas, monospace][color=#f92672] GPIOB_ClearITFlagBit(GPIO_Pin_4);[/color][/font] [font=consolas, monospace][color=#f92672]}[/color][/font] 搜索 [align=left]复制[/align]
3486浏览量 3回复量 关注量