数码之家

 找回密码
 立即注册
搜索
查看: 2313|回复: 37

[STM] 求大佬给stm8s003f3p6编写一个1Khz 的PWM波

[复制链接]
发表于 2022-4-29 15:32:21 | 显示全部楼层 |阅读模式
60家元
本帖最后由 xiaodaishu 于 2022-4-29 18:48 编辑

求大佬给stm8s003f3p6编写一个1Khz 的PWM波。
对一窍不通的我来说简直是天书,怎奈手痒的不行,请大佬帮忙编一个吧。
要求如下:
A.    1kHz   PWM 方波,占空比分别为10%和20%
B.    按下按键占空比在10%和20%之间来回切换。
C.    当10%或20%占空比时分别由不同的指示灯显示,方便辨识是什么状态。
原理图就大概是这样的,不知道我的表达,大神是否看得懂?
184618.png



其实这个主要用于改造电动汽车的随车充,随车的是8A的电流实在是太小了。
一些参考信息如下:
v2-f270a9a386e59f8f284918e6bc8b4116_720w.jpg 22.png

43.png

其他网友的一些制作分享

https://club.m.autohome.com.cn/bbs/thread/381e5136a62aa6a4/84751286-1.html
https://club.m.autohome.com.cn/bbs/thread/0dcdf5b5d470a155/71543133-1.html
https://club.m.autohome.com.cn/bbs/thread/75009d55a8e7b942/71544117-1.html

https://club.m.autohome.com.cn/bbs/thread/3e5bad9c3def73f5/56836072-1.html

有关PWM的介绍
https://zhuanlan.zhihu.com/p/449960070


最佳答案

查看完整内容

10%输出改为PD3,20%输出改为PD4 https://pan.baidu.com/s/1FQbuxb4SHPraRqo0IGUWHA?pwd=9d5b 提取码: 9d5b arduino代码,仅供参考

打赏

参与人数 1家元 +20 收起 理由
springvirus + 20 以資鼓勵

查看全部打赏

发表于 2022-4-29 15:32:22 | 显示全部楼层
10%输出改为PD3,20%输出改为PD4
https://pan.baidu.com/s/1FQbuxb4SHPraRqo0IGUWHA?pwd=9d5b 提取码: 9d5b
arduino代码,仅供参考
  1. #include <Arduino.h>
  2. #include <Serial.h>

  3. unsigned long timeLastGet = 0;

  4. unsigned long timeCnt = 0;

  5. // constants won't change. They're used here to set pin numbers:
  6. const int pinButton = PC5;      // the number of the pushbutton pin
  7. const int pinLed1 = PC4;        // 10% LED pin
  8. const int pinLed2 = PC3;        // 20% LED pin
  9. const int pinPwm1 = PD3;        // 10% output pin
  10. const int pinPwm2 = PD4;        // 20% output pin

  11. // Variables will change:
  12. int pwmState = 0;               // pwm state, 0:10%, 1:20%
  13. int buttonState = LOW;             // the current reading from the input pin
  14. int lastButtonState = LOW;   // the previous reading from the input pin

  15. // the following variables are unsigned longs because the time, measured in
  16. // milliseconds, will quickly become a bigger number than can be stored in an int.
  17. unsigned long lastDebounceTime = 0;  // the last time the output pin was toggled
  18. unsigned long debounceDelay = 50;    // the debounce time; increase if the output flickers

  19. void KeyProcess() {
  20.   // read the state of the switch into a local variable:
  21.   int reading = digitalRead(pinButton);
  22.   //Serial_println_i(reading);
  23.   // check to see if you just pressed the button
  24.   // (i.e. the input went from LOW to HIGH), and you've waited long enough
  25.   // since the last press to ignore any noise:

  26.   // If the switch changed, due to noise or pressing:
  27.   if (reading != lastButtonState) {
  28.     // reset the debouncing timer
  29.     lastDebounceTime = millis();
  30.   }

  31.   if ((millis() - lastDebounceTime) > debounceDelay) {
  32.     // whatever the reading is at, it's been there for longer than the debounce
  33.     // delay, so take it as the actual current state:

  34.     // if the button state has changed:
  35.     if (reading != buttonState) {
  36.       buttonState = reading;

  37.       // only toggle the LED if the new button state is HIGH
  38.       if (buttonState == HIGH) {
  39.         pwmState = 1 - pwmState;
  40.         if (pwmState == 1) {        // 10%
  41.             digitalWrite(pinLed1, HIGH);
  42.             digitalWrite(pinLed2, LOW);
  43.             analogWrite(pinPwm1, 25);
  44.             analogWrite(pinPwm2, 0);
  45.             Serial_print_s("10%");
  46.         } else {
  47.             digitalWrite(pinLed1, LOW);
  48.             digitalWrite(pinLed2, HIGH);
  49.             analogWrite(pinPwm1, 0);
  50.             analogWrite(pinPwm2, 50);
  51.             Serial_print_s("20%");
  52.         }
  53.       }
  54.     }
  55.   }

  56.   // save the reading. Next time through the loop, it'll be the lastButtonState:
  57.   lastButtonState = reading;
  58. }

  59. void setup()
  60. {
  61.     Serial_begin(115200);
  62.     pinMode(pinLed1, OUTPUT);
  63.     pinMode(pinLed2, OUTPUT);
  64.     pinMode(pinPwm1, OUTPUT);
  65.     pinMode(pinPwm2, OUTPUT);
  66.     pinMode(pinButton, INPUT_PULLUP);
  67.     Serial_print_s("PWM generate");
  68. }

  69. void loop()
  70. {
  71.     KeyProcess();
  72. }
复制代码


打赏

参与人数 1家元 +30 收起 理由
xiaodaishu + 30 感谢帮助

查看全部打赏

回复

使用道具 举报

发表于 2022-4-29 16:21:54 来自手机浏览器 | 显示全部楼层
你要画个电路图指定用什么型号单片机别人才能帮你写
回复

使用道具 举报

发表于 2022-4-29 16:29:57 | 显示全部楼层
你的三点要求挺简单的,但是当然不能白干是不,但是作为论坛人,就是玩儿个兴趣,刚好我也没有这种芯片平台,如你能给我快递个这种芯片的样机或者开发板。我给你做做,几块钱的开发板就当酬劳了,有意可以私信。
回复

使用道具 举报

发表于 2022-4-29 17:55:23 | 显示全部楼层
不要求数控的话,NE555搞个可调占空比电路就行了。
回复

使用道具 举报

发表于 2022-4-29 20:00:41 | 显示全部楼层
找个帖子看看也很快就弄了啊
回复

使用道具 举报

发表于 2022-4-29 20:09:22 来自手机浏览器 | 显示全部楼层
TB帮到你,现成的板子
回复

使用道具 举报

发表于 2022-4-29 23:16:11 | 显示全部楼层
cyh68 发表于 2022-4-29 16:21
你要画个电路图指定用什么型号单片机别人才能帮你写

会有人免费写程序?会有人敢用免费的程序?
回复

使用道具 举报

发表于 2022-4-30 07:41:04 来自手机浏览器 | 显示全部楼层
595953427@qq 发表于 2022-4-29 23:16
会有人免费写程序?会有人敢用免费的程序?

这有什么不会的,他这个功能也不多,没什么难度。
回复

使用道具 举报

 楼主| 发表于 2022-4-30 07:43:26 | 显示全部楼层
本帖最后由 xiaodaishu 于 2022-4-30 07:48 编辑
595953427@qq 发表于 2022-4-29 23:16
会有人免费写程序?会有人敢用免费的程序?

都是业余爱好,张口闭口都是金钱,很有商业的味道。愿不愿意是您的自由,不要一棍子打翻所有的人,这里本来就是互相探讨帮助的,论坛帮助的帖子不少,愿意提供帮助的好心人很多,这也是论坛长期存在吸引人的地方,商业味浓的论坛也有,但不适合我这个业余爱好者。

打赏

参与人数 2家元 +66 收起 理由
595953427@qq + 60 精彩回帖
aec + 6 我很贊同

查看全部打赏

回复

使用道具 举报

发表于 2022-4-30 08:25:23 来自手机浏览器 | 显示全部楼层
xiaodaishu 发表于 2022-4-30 07:43
都是业余爱好,张口闭口都是金钱,很有商业的味道。愿不愿意是您的自由,不要一棍子打翻所有的人,这里本 ...

这几天没空,要不我就帮你写了,要是一个星期还没人帮你,我就帮你写了

打赏

参与人数 2家元 +38 收起 理由
xiaodaishu + 20 感谢帮助
aec + 18 熱心助人

查看全部打赏

回复

使用道具 举报

发表于 2022-4-30 12:00:58 | 显示全部楼层
cyh68 发表于 2022-4-30 08:25
这几天没空,要不我就帮你写了,要是一个星期还没人帮你,我就帮你写了 ...

这几天没空,要不我就帮你写了,要是两个星期还没人帮你,我就帮你写了

打赏

参与人数 2家元 +38 收起 理由
xiaodaishu + 20 感谢帮助
aec + 18 熱心會員

查看全部打赏

回复

使用道具 举报

发表于 2022-4-30 13:47:22 | 显示全部楼层
求人不如求己,既然来坛子玩,多少也有点钻研精神吧,看着其他帖子,自己先捣鼓下试试

打赏

参与人数 1家元 +20 收起 理由
xiaodaishu + 20 就怕自己捣鼓的程序存在问题,白费劲,小白.

查看全部打赏

回复

使用道具 举报

发表于 2022-4-30 14:43:24 | 显示全部楼层
不会stm8,也没有stm8开发板。自己看着其他帖子,有开发板自己先捣鼓下试试。
回复

使用道具 举报

发表于 2022-4-30 21:00:45 | 显示全部楼层
这个简单,配置定时器就可以了
回复

使用道具 举报

发表于 2022-5-1 12:38:37 | 显示全部楼层
xiaodaishu 发表于 2022-4-30 07:43
都是业余爱好,张口闭口都是金钱,很有商业的味道。愿不愿意是您的自由,不要一棍子打翻所有的人,这里本 ...

赞同你的说法!
帮不帮是你的自由,不要讽刺别人。想想当你遇到困难需要别人帮助的时候。。。
回复

使用道具 举报

发表于 2022-5-1 13:53:56 来自手机浏览器 | 显示全部楼层
没有示波器要不然就帮你写一下了…
回复

使用道具 举报

发表于 2022-5-1 21:19:43 | 显示全部楼层
如果你不是急着用,可以试着自己学下编程玩玩,玩会了就是另一片天地。
回复

使用道具 举报

发表于 2022-5-2 12:44:15 | 显示全部楼层
慢充就是为了安全的,别瞎折腾了。
回复

使用道具 举报

 楼主| 发表于 2022-5-3 11:29:25 | 显示全部楼层
上官梦舞 发表于 2022-5-2 12:44
慢充就是为了安全的,别瞎折腾了。

它只不过是提供一个协议,安全需要自己根据线材的工作电流来确定,所以只要线材符合规定,应该不存在安全问题。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

APP|手机版|小黑屋|关于我们|联系我们|法律条款|技术知识分享平台

闽公网安备35020502000485号

闽ICP备2021002735号-2

GMT+8, 2024-5-14 16:58 , Processed in 0.405601 second(s), 20 queries , Redis On.

Powered by Discuz!

© 2006-2023 smzj.net

快速回复 返回顶部 返回列表