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

Commit

Permalink
v1.0.0 for PWM Continuous Stepper Control
Browse files Browse the repository at this point in the history
### 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`
  • Loading branch information
khoih-prog committed Jan 24, 2023
1 parent b4eae5e commit dd0c59c
Show file tree
Hide file tree
Showing 27 changed files with 3,621 additions and 1 deletion.
7 changes: 7 additions & 0 deletions .codespellrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# See: https://github.com/codespell-project/codespell#using-a-config-file
[codespell]
# In the event of a false positive, add the problematic word, in all lowercase, to a comma-separated list here:
ignore-words-list = ,
check-filenames =
check-hidden =
skip = ./.git,./src,./examples,./Packages_Patches,./LibraryPatches
79 changes: 79 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
## Contributing to ContinuousStepper_Generic

### Reporting Bugs

Please report bugs in [ContinuousStepper_Generic Issues](https://github.com/khoih-prog/ContinuousStepper_Generic/issues) if you find them.

However, before reporting a bug please check through the following:

* [Existing Open Issues](https://github.com/khoih-prog/ContinuousStepper_Generic/issues) - someone might have already encountered this.

If you don't find anything, please [open a new issue](https://github.com/khoih-prog/ContinuousStepper_Generic/issues/new).

---

### How to submit a bug report

Please ensure to specify the following:

* Arduino IDE version (e.g. 1.8.19) or Platform.io version
* 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.)
* Contextual information (e.g. what you were trying to achieve)
* Simplest possible steps to reproduce
* Anything that might be relevant in your opinion, such as:
* Operating system (Windows, Ubuntu, etc.) and the output of `uname -a`
* Network configuration

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.

---

### Example

```
Arduino IDE version: 1.8.19
Arduino-mbed mbed_nano v3.5.4
NANO_RP2040_CONNECT Module
OS: Ubuntu 21.04 LTS
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
Context:
I encountered a crash while using this library
Steps to reproduce:
1. ...
2. ...
3. ...
4. ...
```

---

### Sending Feature Requests

Feel free to post feature requests. It's helpful if you can explain exactly why the feature would be useful.

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.

---

### Sending Pull Requests

Pull Requests with changes and fixes are also welcome!

Please use the `astyle` to reformat the updated library code as follows (demo for Ubuntu Linux)

1. Change directory to the library GitHub

```
xy@xy-Inspiron-3593:~$ cd Arduino/xy/ContinuousStepper_Generic_GitHub/
xy@xy-Inspiron-3593:~/Arduino/xy/ContinuousStepper_Generic_GitHub$
```

2. Issue astyle command

```
xy@xy-Inspiron-3593:~/Arduino/xy/ContinuousStepper_Generic_GitHub$ bash utils/restyle.sh
```


2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2023 Khoi Hoang
Copyright (c) 2021 Khoi Hoang

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
339 changes: 339 additions & 0 deletions README.md

Large diffs are not rendered by default.

32 changes: 32 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# ContinuousStepper_Generic Library

[![arduino-library-badge](https://www.ardu-badge.com/badge/ContinuousStepper_Generic.svg?)](https://www.ardu-badge.com/ContinuousStepper_Generic)
[![GitHub release](https://img.shields.io/github/release/khoih-prog/ContinuousStepper_Generic.svg)](https://github.com/khoih-prog/ContinuousStepper_Generic/releases)
[![GitHub](https://img.shields.io/github/license/mashape/apistatus.svg)](https://github.com/khoih-prog/ContinuousStepper_Generic/blob/main/LICENSE)
[![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)](#Contributing)
[![GitHub issues](https://img.shields.io/github/issues/khoih-prog/ContinuousStepper_Generic.svg)](http://github.com/khoih-prog/ContinuousStepper_Generic/issues)



<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>
<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>


---
---

## Table of Contents

* [Changelog](#changelog)
* [Initial Releases v1.0.0](#Initial-Releases-v100)

---
---

## Changelog

### 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`

128 changes: 128 additions & 0 deletions examples/ATtiny_PWM_StepperControl/ATtiny_PWM_StepperControl.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
/****************************************************************************************************************************
ATtiny_PWM_StepperControl.ino
For Arduino AVR ATtiny-based boards (ATtiny3217, etc.) using megaTinyCore
Written by Khoi Hoang
Built by Khoi Hoang https://github.com/khoih-prog/ContinuousStepper_Generic
Licensed under MIT license
Credits of Paul van Dinther (https://github.com/dinther). Check https://github.com/khoih-prog/RP2040_PWM/issues/16
*****************************************************************************************************************************/

// Use with Stepper-Motor driver, such as TMC2209

#if !defined(MEGATINYCORE)
#error This is designed only for AVR_ATtiny boards using megaTinyCore
#endif

#define _PWM_LOGLEVEL_ 4

// Select false to use PWM
#define USING_TIMER false //true

#include "ContinuousStepper_Generic.h"

/*
const uint8_t digital_pin_to_timer[] = {
// Left side, top to bottom
TIMERA0, // 0 PA4 WO4 WOA
TIMERA0, // 1 PA5 WO5 WOB
#if defined(DAC0)
DACOUT, // 2 PA6
#else
NOT_ON_TIMER, // 2 PA6
#endif
NOT_ON_TIMER, // 3 PA7
NOT_ON_TIMER, // 4 PB7
NOT_ON_TIMER, // 5 PB6
NOT_ON_TIMER, // 6 PB5 WO2 Alt
NOT_ON_TIMER, // 7 PB4 WO1 Alt
NOT_ON_TIMER, // 8 PB3 WO0 Alt
TIMERA0, // 9 PB2 WO2
TIMERA0, // 10 PB1 WO1
// Right side, bottom to top
TIMERA0, // 11 PB0 WO0
#if (defined(TCD0) && defined(USE_TIMERD0_PWM))
TIMERD0, // 12 PC0 WOC
TIMERD0, // 13 PC1 WOD
#else
NOT_ON_TIMER, // 12 PC0
NOT_ON_TIMER, // 13 PC1
#endif
NOT_ON_TIMER, // 14 PC2
NOT_ON_TIMER, // 15 PC3 WO3 Alt
NOT_ON_TIMER, // 16 PC4 WO4 Alt
NOT_ON_TIMER, // 17 PC5 WO5 Alt
NOT_ON_TIMER, // 18 PA1
NOT_ON_TIMER, // 19 PA2
TIMERA0, // 20 PA3 WO3
NOT_ON_TIMER // 21 PA0
};
*/

// OK, only PIN_PA4-5:TCA0
// PIN_PC0-1: TCD0 => not OK yet for frequency
// Not OK, PIN_PA6, 7, PIN_PB0-2:TCA0

#define STEP_PIN PIN_PA5 //PIN_PB4

#define DIR_PIN PIN_PA6

ATtiny_PWM* stepper;

// The Stepper RPM will be ( speed * 60 ) / steps-per-rev
// For example, 28BYJ-48 Stepper Motor (https://lastminuteengineers.com/28byj48-stepper-motor-arduino-tutorial/) has 32 Steps/Rev
// Speed = 640 Hz => Stepper RPM = (640 * 60 / 32) = 1200 RPM
void setSpeed(int speed)
{
if (speed == 0)
{
// Use DC = 0 to stop stepper
stepper->setPWM(STEP_PIN, 500, 0);
}
else
{
// Set the frequency of the PWM output and a duty cycle of 50%
digitalWrite(DIR_PIN, (speed < 0));
stepper->setPWM(STEP_PIN, abs(speed), 50);
}
}

void setup()
{
pinMode(DIR_PIN, OUTPUT);

Serial.begin(115200);

while (!Serial && millis() < 5000);

delay(100);

Serial.print(F("\nStarting ATtiny_PWM_StepperControl on "));
Serial.println(BOARD_NAME);
Serial.println(AT_TINY_PWM_VERSION);
Serial.println(CONTINUOUS_STEPPER_GENERIC_VERSION);

// Create PWM object and passed just a random frequency of 500
// The duty cycle is how you turn the motor on and off
stepper = new ATtiny_PWM(STEP_PIN, 500, 0);
}

void loop()
{
// The Stepper RPM will be ( speed * 60 ) / steps-per-rev
setSpeed(1000);
delay(3000);

// Stop before reversing
setSpeed(0);
delay(3000);

// Reversing
setSpeed(-500);
delay(3000);

// Stop before reversing
setSpeed(0);
delay(3000);
}
Loading

0 comments on commit dd0c59c

Please sign in to comment.