Skip to content
This repository was archived by the owner on Feb 4, 2023. It is now read-only.

Commit dd0c59c

Browse files
authored
v1.0.0 for PWM Continuous Stepper Control
### Initial Releases v1.0.0 1. Initial coding to use PWM to control continuous Stepper Motor. Check [Using PWM to step a stepper driver #16](https://github.com/khoih-prog/ContinuousStepper_Generic/issues/16) 2. Use `allman astyle` and add `utils`
1 parent b4eae5e commit dd0c59c

File tree

27 files changed

+3621
-1
lines changed

27 files changed

+3621
-1
lines changed

.codespellrc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# See: https://github.com/codespell-project/codespell#using-a-config-file
2+
[codespell]
3+
# In the event of a false positive, add the problematic word, in all lowercase, to a comma-separated list here:
4+
ignore-words-list = ,
5+
check-filenames =
6+
check-hidden =
7+
skip = ./.git,./src,./examples,./Packages_Patches,./LibraryPatches

CONTRIBUTING.md

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
## Contributing to ContinuousStepper_Generic
2+
3+
### Reporting Bugs
4+
5+
Please report bugs in [ContinuousStepper_Generic Issues](https://github.com/khoih-prog/ContinuousStepper_Generic/issues) if you find them.
6+
7+
However, before reporting a bug please check through the following:
8+
9+
* [Existing Open Issues](https://github.com/khoih-prog/ContinuousStepper_Generic/issues) - someone might have already encountered this.
10+
11+
If you don't find anything, please [open a new issue](https://github.com/khoih-prog/ContinuousStepper_Generic/issues/new).
12+
13+
---
14+
15+
### How to submit a bug report
16+
17+
Please ensure to specify the following:
18+
19+
* Arduino IDE version (e.g. 1.8.19) or Platform.io version
20+
* Board Core Version (e.g. Arduino SAMDUE core v1.6.12, ESP32 core v2.0.6, ESP8266 core v3.1.1, ArduinoCore-mbed v3.5.4, etc.)
21+
* Contextual information (e.g. what you were trying to achieve)
22+
* Simplest possible steps to reproduce
23+
* Anything that might be relevant in your opinion, such as:
24+
* Operating system (Windows, Ubuntu, etc.) and the output of `uname -a`
25+
* Network configuration
26+
27+
Please be educated, civilized and constructive as you've always been. Disrespective posts against [GitHub Code of Conduct](https://docs.github.com/en/site-policy/github-terms/github-event-code-of-conduct) will be ignored and deleted.
28+
29+
---
30+
31+
### Example
32+
33+
```
34+
Arduino IDE version: 1.8.19
35+
Arduino-mbed mbed_nano v3.5.4
36+
NANO_RP2040_CONNECT Module
37+
OS: Ubuntu 21.04 LTS
38+
Linux xy-Inspiron-3593 5.15.0-58-generic #64~20.04.1-Ubuntu SMP Fri Jan 6 16:42:31 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux
39+
40+
Context:
41+
I encountered a crash while using this library
42+
43+
Steps to reproduce:
44+
1. ...
45+
2. ...
46+
3. ...
47+
4. ...
48+
```
49+
50+
---
51+
52+
### Sending Feature Requests
53+
54+
Feel free to post feature requests. It's helpful if you can explain exactly why the feature would be useful.
55+
56+
There are usually some outstanding feature requests in the [existing issues list](https://github.com/khoih-prog/ContinuousStepper_Generic/issues?q=is%3Aopen+is%3Aissue+label%3Aenhancement), feel free to add comments to them.
57+
58+
---
59+
60+
### Sending Pull Requests
61+
62+
Pull Requests with changes and fixes are also welcome!
63+
64+
Please use the `astyle` to reformat the updated library code as follows (demo for Ubuntu Linux)
65+
66+
1. Change directory to the library GitHub
67+
68+
```
69+
xy@xy-Inspiron-3593:~$ cd Arduino/xy/ContinuousStepper_Generic_GitHub/
70+
xy@xy-Inspiron-3593:~/Arduino/xy/ContinuousStepper_Generic_GitHub$
71+
```
72+
73+
2. Issue astyle command
74+
75+
```
76+
xy@xy-Inspiron-3593:~/Arduino/xy/ContinuousStepper_Generic_GitHub$ bash utils/restyle.sh
77+
```
78+
79+

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2023 Khoi Hoang
3+
Copyright (c) 2021 Khoi Hoang
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 339 additions & 0 deletions
Large diffs are not rendered by default.

changelog.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# ContinuousStepper_Generic Library
2+
3+
[![arduino-library-badge](https://www.ardu-badge.com/badge/ContinuousStepper_Generic.svg?)](https://www.ardu-badge.com/ContinuousStepper_Generic)
4+
[![GitHub release](https://img.shields.io/github/release/khoih-prog/ContinuousStepper_Generic.svg)](https://github.com/khoih-prog/ContinuousStepper_Generic/releases)
5+
[![GitHub](https://img.shields.io/github/license/mashape/apistatus.svg)](https://github.com/khoih-prog/ContinuousStepper_Generic/blob/main/LICENSE)
6+
[![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)](#Contributing)
7+
[![GitHub issues](https://img.shields.io/github/issues/khoih-prog/ContinuousStepper_Generic.svg)](http://github.com/khoih-prog/ContinuousStepper_Generic/issues)
8+
9+
10+
11+
<a href="https://www.buymeacoffee.com/khoihprog6" title="Donate to my libraries using BuyMeACoffee"><img src="https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png" alt="Donate to my libraries using BuyMeACoffee" style="height: 50px !important;width: 181px !important;" ></a>
12+
<a href="https://www.buymeacoffee.com/khoihprog6" title="Donate to my libraries using BuyMeACoffee"><img src="https://img.shields.io/badge/buy%20me%20a%20coffee-donate-orange.svg?logo=buy-me-a-coffee&logoColor=FFDD00" style="height: 20px !important;width: 200px !important;" ></a>
13+
14+
15+
---
16+
---
17+
18+
## Table of Contents
19+
20+
* [Changelog](#changelog)
21+
* [Initial Releases v1.0.0](#Initial-Releases-v100)
22+
23+
---
24+
---
25+
26+
## Changelog
27+
28+
### Initial Releases v1.0.0
29+
30+
1. Initial coding to use PWM to control continuous Stepper Motor. Check [Using PWM to step a stepper driver #16](https://github.com/khoih-prog/ContinuousStepper_Generic/issues/16)
31+
2. Use `allman astyle` and add `utils`
32+
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
/****************************************************************************************************************************
2+
ATtiny_PWM_StepperControl.ino
3+
For Arduino AVR ATtiny-based boards (ATtiny3217, etc.) using megaTinyCore
4+
Written by Khoi Hoang
5+
6+
Built by Khoi Hoang https://github.com/khoih-prog/ContinuousStepper_Generic
7+
Licensed under MIT license
8+
9+
Credits of Paul van Dinther (https://github.com/dinther). Check https://github.com/khoih-prog/RP2040_PWM/issues/16
10+
*****************************************************************************************************************************/
11+
12+
// Use with Stepper-Motor driver, such as TMC2209
13+
14+
#if !defined(MEGATINYCORE)
15+
#error This is designed only for AVR_ATtiny boards using megaTinyCore
16+
#endif
17+
18+
#define _PWM_LOGLEVEL_ 4
19+
20+
// Select false to use PWM
21+
#define USING_TIMER false //true
22+
23+
#include "ContinuousStepper_Generic.h"
24+
25+
/*
26+
const uint8_t digital_pin_to_timer[] = {
27+
// Left side, top to bottom
28+
TIMERA0, // 0 PA4 WO4 WOA
29+
TIMERA0, // 1 PA5 WO5 WOB
30+
#if defined(DAC0)
31+
DACOUT, // 2 PA6
32+
#else
33+
NOT_ON_TIMER, // 2 PA6
34+
#endif
35+
NOT_ON_TIMER, // 3 PA7
36+
NOT_ON_TIMER, // 4 PB7
37+
NOT_ON_TIMER, // 5 PB6
38+
NOT_ON_TIMER, // 6 PB5 WO2 Alt
39+
NOT_ON_TIMER, // 7 PB4 WO1 Alt
40+
NOT_ON_TIMER, // 8 PB3 WO0 Alt
41+
TIMERA0, // 9 PB2 WO2
42+
TIMERA0, // 10 PB1 WO1
43+
// Right side, bottom to top
44+
TIMERA0, // 11 PB0 WO0
45+
#if (defined(TCD0) && defined(USE_TIMERD0_PWM))
46+
TIMERD0, // 12 PC0 WOC
47+
TIMERD0, // 13 PC1 WOD
48+
#else
49+
NOT_ON_TIMER, // 12 PC0
50+
NOT_ON_TIMER, // 13 PC1
51+
#endif
52+
NOT_ON_TIMER, // 14 PC2
53+
NOT_ON_TIMER, // 15 PC3 WO3 Alt
54+
NOT_ON_TIMER, // 16 PC4 WO4 Alt
55+
NOT_ON_TIMER, // 17 PC5 WO5 Alt
56+
NOT_ON_TIMER, // 18 PA1
57+
NOT_ON_TIMER, // 19 PA2
58+
TIMERA0, // 20 PA3 WO3
59+
NOT_ON_TIMER // 21 PA0
60+
};
61+
*/
62+
63+
// OK, only PIN_PA4-5:TCA0
64+
// PIN_PC0-1: TCD0 => not OK yet for frequency
65+
// Not OK, PIN_PA6, 7, PIN_PB0-2:TCA0
66+
67+
#define STEP_PIN PIN_PA5 //PIN_PB4
68+
69+
#define DIR_PIN PIN_PA6
70+
71+
ATtiny_PWM* stepper;
72+
73+
// The Stepper RPM will be ( speed * 60 ) / steps-per-rev
74+
// For example, 28BYJ-48 Stepper Motor (https://lastminuteengineers.com/28byj48-stepper-motor-arduino-tutorial/) has 32 Steps/Rev
75+
// Speed = 640 Hz => Stepper RPM = (640 * 60 / 32) = 1200 RPM
76+
void setSpeed(int speed)
77+
{
78+
if (speed == 0)
79+
{
80+
// Use DC = 0 to stop stepper
81+
stepper->setPWM(STEP_PIN, 500, 0);
82+
}
83+
else
84+
{
85+
// Set the frequency of the PWM output and a duty cycle of 50%
86+
digitalWrite(DIR_PIN, (speed < 0));
87+
stepper->setPWM(STEP_PIN, abs(speed), 50);
88+
}
89+
}
90+
91+
void setup()
92+
{
93+
pinMode(DIR_PIN, OUTPUT);
94+
95+
Serial.begin(115200);
96+
97+
while (!Serial && millis() < 5000);
98+
99+
delay(100);
100+
101+
Serial.print(F("\nStarting ATtiny_PWM_StepperControl on "));
102+
Serial.println(BOARD_NAME);
103+
Serial.println(AT_TINY_PWM_VERSION);
104+
Serial.println(CONTINUOUS_STEPPER_GENERIC_VERSION);
105+
106+
// Create PWM object and passed just a random frequency of 500
107+
// The duty cycle is how you turn the motor on and off
108+
stepper = new ATtiny_PWM(STEP_PIN, 500, 0);
109+
}
110+
111+
void loop()
112+
{
113+
// The Stepper RPM will be ( speed * 60 ) / steps-per-rev
114+
setSpeed(1000);
115+
delay(3000);
116+
117+
// Stop before reversing
118+
setSpeed(0);
119+
delay(3000);
120+
121+
// Reversing
122+
setSpeed(-500);
123+
delay(3000);
124+
125+
// Stop before reversing
126+
setSpeed(0);
127+
delay(3000);
128+
}

0 commit comments

Comments
 (0)