完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
我一直在为面包板上的STM8S103F3开发一些应用程序,我最近将其中一个项目转移到了STM8S Discovery板上,我发现了一些我无法解决的行为差异。
该程序使用PWM模式2在定时器1通道3上输出60 uS方波。在面包板上的STM8S103F3上,程序工作正常,我得到0到3.3V的方波。 在发现板上,我的方波具有正确的频率,但输出电压峰峰值仅为280 mV。我连接到Discovery板的唯一事情是USB连接和连接到定时器输出和接地的示波器。 我使用IAR作为开发环境,并相应地修改了包含文件和项目选项。 我可能会出错的任何想法?我是否正确假设如果应用程序在STM8S103F3上运行,那么它将在Discovery板上运行,假设我更改了包含文件和目标芯片? 该应用程序的代码包含在下面。 问候, 标记 & sharpinclude< intrinsics.h> & sharpinclude< iostm8s103f3.h> // //使用内部振荡器将系统时钟设置为16MHz。 // void InitialiseSystemClock() { CLK_ICKR = 0; //重置内部时钟寄存器。 CLK_ICKR_HSIEN = 1; //启用HSI。 CLK_ECKR = 0; //禁用外部时钟。 while(CLK_ICKR_HSIRDY == 0); //等待HSI准备好使用。 CLK_CKDIVR = 0; //确保时钟全速运行。 CLK_PCKENR1 = 0xff; //启用所有外设时钟。 CLK_PCKENR2 = 0xff; //同上 CLK_CCOR = 0; //关闭CCO。 CLK_HSITRIMR = 0; //关闭任何HSIU修剪。 CLK_SWIMCCR = 0; //将SWIM设置为以时钟/ 2运行。 CLK_SWR = 0xe1; //使用HSI作为时钟源。 CLK_SWCR = 0; //复位时钟切换控制寄存器。 CLK_SWCR_SWEN = 1; //启用切换。 while(CLK_SWCR_SWBSY!= 0); //时钟开关忙时暂停 } // //初始化计时器1。 // void InitialiseTimer1() { TIM1_CR1 = 0; TIM1_CR2 = 0; TIM1_SMCR = 0; TIM1_ETR = 0; TIM1_IER = 0; TIM1_SR2 = 0; TIM1_CCER1 = 0; TIM1_CCER2 = 0; TIM1_CCMR1 = 0; TIM1_CCMR2 = 0; TIM1_CCMR3 = 0; TIM1_CCMR4 = 0; TIM1_CCER1 = 0; TIM1_CCER2 = 0; TIM1_CCMR1 = 0; TIM1_CCMR2 = 0; TIM1_CCMR3 = 0; TIM1_CCMR4 = 0; TIM1_CNTRH = 0; TIM1_CNTRL = 0; TIM1_PSCRH = 0; TIM1_PSCRL = 0; TIM1_ARRH = 0; TIM1_ARRL = 0; TIM1_CCR1H = 0; TIM1_CCR1L = 0; TIM1_CCR2H = 0; TIM1_CCR2L = 0; TIM1_CCR3H = 0; TIM1_CCR3L = 0; TIM1_CCR4H = 0; TIM1_CCR4L = 0; TIM1_OISR = 0; TIM1_EGR = 0x01; TIM1_DTR = 0; TIM1_BKR = 0; TIM1_RCR = 0; TIM1_SR1 = 0; } // //设置定时器1,通道3输出持续30 uS的单脉冲。 // void SetupTimer1() { TIM1_ARRH = 0x03; //重新加载计数器= 960 TIM1_ARRL = 0xc0; TIM1_PSCRH = 0; // Prescalar = 0(即1) TIM1_PSCRL = 0; TIM1_CR1_DIR = 0; //向上计数器。 TIM1_CR1_CMS = 0; //边缘对齐计数器。 TIM1_RCR = 0; //没有重复 // //现在配置定时器1,通道3。 // TIM1_CCMR3_OC3M = 7; //设置为使用PWM模式2。 TIM1_CCER2_CC3E = 1; //输出已启用。 TIM1_CCER2_CC3P = 0; // Active定义为高。 TIM1_CCR3H = 0x01; // 480 = 50%占空比(基于TIM1_ARR)。 TIM1_CCR3L = 0xe0; TIM1_BKR_MOE = 1; //启用主输出。 // TIM1_CR1_OPM = 1; TIM1_CR1_CEN = 1; } // //主程序循环 // void main() { // //初始化系统。 // __disable_interrupt(); InitialiseSystemClock(); InitialiseTimer1(); SetupTimer1(); __enable_interrupt(); 而(1) { __wait_for_interrupt(); } } #stm8s103f3发现定时器 以上来自于谷歌翻译 以下为原文 I have been developing some applications for the STM8S103F3 which I have on breadboard and I have recently transferred one of the projects to the STM8S Discovery board and I am finding a difference in behaviour which I cannot work out. The program uses PWM Mode 2 to output a 60 uS square wave on timer 1 channel3. On the STM8S103F3 on breadboard the program works fine and I get a 0 to 3.3V square wave. On the Discovery board I have the square wave with the right frequency but the output voltage is only 280 mV peak-to-peak. The only things I have connected to the Discovery board are the USB connection and the scope connected to the timer output and ground. I am using IAR as the development environment and I have modified the include files and project options accordingly. Any ideas where I could be going wrong? Am I correct in assuming that if the app runs on the STM8S103F3 then it will run on the Discovery board assuming I change the include file and target chip? The code for the application is included below. Regards, Mark &sharpinclude &sharpinclude // // Setup the system clock to run at 16MHz using the internal oscillator. // void InitialiseSystemClock() { CLK_ICKR = 0; // Reset the Internal Clock Register. CLK_ICKR_HSIEN = 1; // Enable the HSI. CLK_ECKR = 0; // Disable the external clock. while (CLK_ICKR_HSIRDY == 0); // Wait for the HSI to be ready for use. CLK_CKDIVR = 0; // Ensure the clocks are running at full speed. CLK_PCKENR1 = 0xff; // Enable all peripheral clocks. CLK_PCKENR2 = 0xff; // Ditto. CLK_CCOR = 0; // Turn off CCO. CLK_HSITRIMR = 0; // Turn off any HSIU trimming. CLK_SWIMCCR = 0; // Set SWIM to run at clock / 2. CLK_SWR = 0xe1; // Use HSI as the clock source. CLK_SWCR = 0; // Reset the clock switch control register. CLK_SWCR_SWEN = 1; // Enable switching. while (CLK_SWCR_SWBSY != 0); // Pause while the clock switch is busy. } // // Initialise Timer 1. // void InitialiseTimer1() { TIM1_CR1 = 0; TIM1_CR2 = 0; TIM1_SMCR = 0; TIM1_ETR = 0; TIM1_IER = 0; TIM1_SR2 = 0; TIM1_CCER1 = 0; TIM1_CCER2 = 0; TIM1_CCMR1 = 0; TIM1_CCMR2 = 0; TIM1_CCMR3 = 0; TIM1_CCMR4 = 0; TIM1_CCER1 = 0; TIM1_CCER2 = 0; TIM1_CCMR1 = 0; TIM1_CCMR2 = 0; TIM1_CCMR3 = 0; TIM1_CCMR4 = 0; TIM1_CNTRH = 0; TIM1_CNTRL = 0; TIM1_PSCRH = 0; TIM1_PSCRL = 0; TIM1_ARRH = 0; TIM1_ARRL = 0; TIM1_CCR1H = 0; TIM1_CCR1L = 0; TIM1_CCR2H = 0; TIM1_CCR2L = 0; TIM1_CCR3H = 0; TIM1_CCR3L = 0; TIM1_CCR4H = 0; TIM1_CCR4L = 0; TIM1_OISR = 0; TIM1_EGR = 0x01; TIM1_DTR = 0; TIM1_BKR = 0; TIM1_RCR = 0; TIM1_SR1 = 0; } // // Set up Timer 1, channel 3 to output a single pulse lasting 30 uS. // void SetupTimer1() { TIM1_ARRH = 0x03; // Reload counter = 960 TIM1_ARRL = 0xc0; TIM1_PSCRH = 0; // Prescalar = 0 (i.e. 1) TIM1_PSCRL = 0; TIM1_CR1_DIR = 0; // Up counter. TIM1_CR1_CMS = 0; // Edge aligned counter. TIM1_RCR = 0; // No repetition. // // Now configure Timer 1, channel 3. // TIM1_CCMR3_OC3M = 7; // Set up to use PWM mode 2. TIM1_CCER2_CC3E = 1; // Output is enabled. TIM1_CCER2_CC3P = 0; // Active is defined as high. TIM1_CCR3H = 0x01; // 480 = 50% duty cycle (based on TIM1_ARR). TIM1_CCR3L = 0xe0; TIM1_BKR_MOE = 1; // Enable the main output. // TIM1_CR1_OPM = 1; TIM1_CR1_CEN = 1; } // // Main program loop. // void main() { // // Initialise the system. // __disable_interrupt(); InitialiseSystemClock(); InitialiseTimer1(); SetupTimer1(); __enable_interrupt(); while (1) { __wait_for_interrupt(); } } #stm8s103f3-discovery-timer |
|
相关推荐
1个回答
|
|
完成了这一项(在朋友的帮助下)。问题是输出Tim1Ch3信号的引脚连接到触摸传感器。我将频道改为Tim1Ch4,一切都很好看。
我可以删除连接,因为手册告诉你如何做到这一点,但我想我先尝试非侵入性路线。 问候, 标记 以上来自于谷歌翻译 以下为原文 Worked this one out (with the help from a friend). The problem is that the pin outputting the Tim1Ch3 signal is connected to the touch sensor. I changed the channel to Tim1Ch4 and everything is looking good. I could have removed the connection as the manual tells you how to do this but I thought I'd try the non-invasive route first. Regards, Mark |
|
|
|
只有小组成员才能发言,加入小组>>
请教:在使用UDE STK时,单片机使用SPC560D30L1,在配置文件怎么设置或选择?里面只有SPC560D40的选项
2747 浏览 1 评论
3244 浏览 1 评论
请问是否有通过UART连接的两个微处理器之间实现双向值交换的方法?
1813 浏览 1 评论
3655 浏览 6 评论
6044 浏览 21 评论
1342浏览 4评论
204浏览 3评论
对H747I-DISCO写程序时将CN2的st-link复用为usart1,再次烧录时无法检测到stlink怎么解决?
359浏览 2评论
STM32G474RE芯片只是串口发个数据就发烫严重是怎么回事?
449浏览 2评论
STM32处理增量式编码器Z信号如何判断中断是正转的还是反向转的?
277浏览 2评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-29 05:58 , Processed in 1.359626 second(s), Total 75, Slave 59 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号