8118 views|2 replies

280

Posts

0

Resources
The OP
 

【XMC4800 Relax EtherCAT Kit Review】+ Getting Started with DAVE, PWM Module Application [Copy link]

Today I will continue to share how to use the PWM module. Today I will use the PWM module to make a breathing light application and print out the relevant setting values from the serial port. The specific steps are as follows:
1. Add PWM, INTERRUPT (add 2), and UART modules.
Second, set the PWM module and pay attention to the value set in the red box. The frequency setting is the frequency setting of the PWM signal, and the DUTY duty cycle is the high level period within a cycle, which is set to 50% here.
Select event setting. Here, select 2 events. Compare is used to match the waveform duty cycle setting, and period is used to match the cycle time. , sans-serif]
The specific event explanation is as follows:
Set up the HW signal connection of the PWM module. The specific screenshot is as follows:
Fourth, configure the UART settings. Set it to the non-interrupt mode of transmission mode, 9600-8-1-n.
Five, write the main program. Add the compare_match_handler() and period_match_handler() interrupt handling functions respectively.
The specific code is as follows. Here, the duty cycle is continuously increased and then reduced after reaching the maximum value. In addition, another LED is periodically flipped to check whether the period_match_handler() function is executed.
  1. /* * main.c * * Created on: 2019 Jan 29 21:23:36 * Author: ???? */ #include<dave.h> //Declarations from DAVE Code Generation (includes SFR declaration)
  2. /**
  3. * [url=home.php?mod=space&amp;uid=159083]@brief[/url] main() - Application entry point
  4. *
  5. * <b>Details of function</b><br/>
  6. * This routine is the application entry point. It is invoked by the device startup code. It is responsible for
  7. * invoking the APP initialization dispatcher routine - DAVE_Init() and hosting the place-holder for user application
  8. * code.
  9. */
  10. static uint32_t duty =100;
  11. uint8_t value[10];
  12. int main(void)
  13. {
  14. DAVE_STATUS_t status;
  15. status = DAVE_Init(); /* Initialization of DAVE APPs */
  16. if(status != DAVE_STATUS_SUCCESS)
  17. {
  18. /* Placeholder for error handler code. The while loop below can be replaced with an user error handler. */
  19. XMC_DEBUG("DAVE APPs initialization failed\n");
  20. while(1U)
  21. {
  22. }
  23. }
  24. PWM_Start(&amp;PWM_0);
  25. /* Placeholder for user application code. The while loop below can be replaced with user application code. */
  26. while(1U)
  27. {
  28. sprintf(value,"%d",duty);
  29. UART_Transmit(&amp;UART_0,"Duty Set Value:",15);
  30. UART_Transmit(&amp;UART_0,value,sizeof(value));
  31. UART_Transmit(&amp;UART_0,"\r\n",2);
  32. }
  33. }
  34. void compare_match_handler()
  35. {
  36. static bool decrement_duty =(bool)false;
  37. if(decrement_duty != false)
  38. {
  39. duty =duty-100;
  40. if (duty &lt;= 100)
  41. {
  42. decrement_duty = false;
  43. }
  44. }
  45. else
  46. {
  47. duty =duty+100;
  48. if (duty &gt;= 10000)
  49. {
  50. decrement_duty = true;
  51. }
  52. }
  53. PWM_SetDutyCycle(&amp;PWM_0,duty);
  54. PWM_ClearEvent(&amp;PWM_0,PWM_INTERRUPT_COMPAREMATCH );
  55. }
  56. void period_match_handler(){
  57. DIGITAL_IO_ToggleOutput(&amp;LED_1);
  58. PWM_ClearEvent(&amp;PWM_0,PWM_INTERRUPT_PERIODMATCH );
  59. }
复制代码
七、   编译下载运行程序,结果如下。两个led灯一个灯会呼吸,一个led灯会闪烁。
程序运行也录好了视频,网络问题无法上传,后续会更新相关的视频。

另外使用DAVE的APP模式编程时需要注意,只要对APP模块的应用做了修改,就必须重新产生代码,必须重新产生代码,必须重新产生代码。
好了,今天分享结束。

下次继续分享,同时之前也按照其他网友的帖子跑了跑lwip和http服务器,我会将具体操作过程细化,后面再跟大家分享一下。



Latest reply

I only saw the configuration of the flashing light, but not the configuration of the breathing light. Can you please provide detailed steps?   Details Published on 2020-12-4 17:16
 

3

Posts

0

Resources
2
 
Thank you for sharing
 
 

5

Posts

0

Resources
3
 

I only saw the configuration of the flashing light, but not the configuration of the breathing light. Can you please provide detailed steps?

 
 

Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list