完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
电子发烧友论坛|
我有STMT / 8L-EV1,当按下其中一个方向按钮时,我想产生4KHz的哔哔声。似乎直截了当但我不确定如何实现它。我试过使用并打开和关闭GPIO引脚无济于事。我已经尝试将PWM用于tiM1_Channel2,蜂鸣器已开启,但这也无效。我不希望将嘟嘟声绑定到计时器或中断。我需要的只是一个打开它的功能和一个关闭它的功能。
有任何想法吗?谢谢。 #stm8 #beep#stm8l 以上来自于谷歌翻译 以下为原文 I have the STMT/8L-EV1 and I'd like to generate a 4KHz beep sound when one of the directional buttons is pressed. Seems straight forward but I'm not sure how to implement it. I've tried just using and turning the GPIO pin on and off to no avail. I've tried to use the PWM for the TIM1_Channel2 the buzzer is on but that didn't work either. I don't want the beep tied to a timer or interrupt. All I need is a function to turn it on and one to turn it off. Any ideas? Thanks. #stm8 #beep #stm8l |
|
相关推荐
5个回答
|
|
|
你好
“我有STMT / 8L-EV1,我想产生4KHz的哔哔声” ''我已经尝试将PWM用于TIM1_Channel2,蜂鸣器已开启,但这也无效。'' IO引脚可能没有足够的驱动器直接驱动蜂鸣器。你需要一个晶体管或某种驱动放大器。 “我不想把哔哔声挂在计时器上” 仅使用代码很难获得常规的开/关时段。使用定时器(在PWM模式下)更容易。 如果你不介意STM8被捆绑只是切换IO端口,那么就可以完成。 以上来自于谷歌翻译 以下为原文 Hi ''I have the STMT/8L-EV1 and I'd like to generate a 4KHz beep sound'' ''I've tried to use the PWM for the TIM1_Channel2 the buzzer is on but that didn't work either.'' The IO pin probably does not have enough drive to drive the buzzer directly. You will needs a transistor or some kind of driver amp. '' I don't want the beep tied to a timer'' Very difficult to get a regular on/off period just using code. It is easier to use the timer (in PWM mode) to do this. If you do not mind the STM8 being tied up just toggling the IO port then it can be done. |
|
|
|
|
|
我懂了。
我仔细查看了评估板的演示代码,发现了两个打开和关闭PWM的功能。但是,我在我自己的代码中调用这些函数,它们不起作用。有什么想法吗? void PlayPWM(u16 freq) { u16责任周期; if(freq!= 0) { / *设定频率* / TIM1-> ARRH =(u8)(freq> 8); TIM1-> ARRL =(u8)(freq); / *设置占空比= freq / 2 = 50%* / dutycycle =(u16)(freq>> 4); TIM1-> CCR2H =(u8)(占空比> 8); TIM1-> CCR2L =(u8)(占空比); / *启用OCN2 * / TIM1-> CCER1 | = 0x40; } } void StopPWM(void) { / *禁用OCN2 * / TIM1-> CCER1& =(u8)(~0x40); } 以上来自于谷歌翻译 以下为原文 I see. I've looked through the demo code from the eval board and found this, two functions to turn the PWM on and off. However I go and call these functions in my own code, they do not work. Any thoughts? void PlayPWM(u16 freq) { u16 dutycycle; if (freq != 0) { /* Set frequency */ TIM1->ARRH = (u8)(freq >> 8); TIM1->ARRL = (u8)(freq); /* Set duty cycle = freq/2 = 50% */ dutycycle = (u16)(freq >> 4); TIM1->CCR2H = (u8)(dutycycle >> 8); TIM1->CCR2L = (u8)(dutycycle); /* Enable OCN2 */ TIM1->CCER1 |= 0x40; } } void StopPWM(void) { /* Disable OCN2 */ TIM1->CCER1 &= (u8)(~0x40); } |
|
|
|
|
|
你好
我不熟悉STM8,因为我使用的是STM32F4系列。 您是否已将IO引脚配置为输出定时器输出而不是 IO? 以上来自于谷歌翻译 以下为原文 Hi I am no familiar with the STM8 because I work with STM32F4 series. Have you configured the IO pin to output the timer output instead of IO ? |
|
|
|
|
|
初始化和配置引脚的功能是
GPIO_Init(GPIOE,GPIO_Pin_1,GPIO_Mode_Out_PP_Low_Fast); 我不知道,或者还没有找到一种方法来配置实际的定时器引脚。 以上来自于谷歌翻译 以下为原文 The function to initialize and configure the pin is GPIO_Init(GPIOE, GPIO_Pin_1, GPIO_Mode_Out_PP_Low_Fast); I don't know, or haven't found a way to configure the actual pin to the timer. |
|
|
|
|
|
您是否查看了所用设备的参考手册?
''备用功能输出提供从外设到输出或I / O焊盘的直接路径,优先于数据输出锁存寄存器(Px_ODR)中的端口位,并强制Px_DDR对应位为1.备用功能输出可以是推挽式或伪开漏式,具体取决于外设和控制寄存器1(Px_CR1),并且可以根据控制寄存器2(Px_CR2)值控制斜率。 以上来自于谷歌翻译 以下为原文 Have you checked the reference manual for the device you are using? ''Alternate function outputs provide a direct path from a peripheral to an output or to an I/O pad, taking precedence over the port bit in the data output latch register (Px_ODR) and forcing the Px_DDR corresponding bit to 1. An alternate function output can be push-pull or pseudo-open drain depending on the peripheral and Control register 1 (Px_CR1) and slope can be controlled depending on the Control register 2 (Px_CR2) values.'' |
|
|
|
|
只有小组成员才能发言,加入小组>>
stm32mp157的异核通信的rpmsg_sdb的m4固件和a7驱动该如何编写?
1453 浏览 0 评论
stm32f103用freertos对一个采样率为1kHz的传感器,进行采样,数据出差
1502 浏览 0 评论
请教:在使用UDE STK时,单片机使用SPC560D30L1,在配置文件怎么设置或选择?里面只有SPC560D40的选项
3649 浏览 1 评论
3842 浏览 1 评论
请问是否有通过UART连接的两个微处理器之间实现双向值交换的方法?
2461 浏览 1 评论
STM32H7打开DCache后,出现了串口接收信息为空的现象,是哪里出了问题?
727浏览 5评论
用NANO STM32F103RBT6的开发板烧录不了是哪里出了问题?
663浏览 5评论
710浏览 5评论
外部中断触发类型为双边沿触发,进入中断回调后有什么办法判断该边沿是上升沿还是下降沿?
941浏览 5评论
STM32L071CBT6低温环境下无法正常工作是什么原因引起的?
745浏览 5评论
/9
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2025-12-2 09:21 , Processed in 0.553790 second(s), Total 50, Slave 43 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191

淘帖
3028