This repository has been archived by the owner on Feb 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
v1.0.1 to add
PWM_StepperControl
example
### Releases v1.0.1 1. Add example [PWM_StepperControl](https://github.com/khoih-prog/SAMDUE_PWM/tree/main/examples/PWM_StepperControl) to demo how to control Stepper Motor using PWM
- Loading branch information
1 parent
0f86358
commit e9f074c
Showing
8 changed files
with
127 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/**************************************************************************************************************************** | ||
PWM_StepperControl.ino | ||
For SAM_DUE boards using hardware-based PWM | ||
Written by Khoi Hoang | ||
Built by Khoi Hoang https://github.com/khoih-prog/SAMDUE_PWM | ||
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 | ||
|
||
#define _PWM_LOGLEVEL_ 4 | ||
|
||
// Select false to use PWM | ||
#define USING_TIMER true | ||
|
||
#include "SAMDUE_PWM.h" | ||
|
||
// SAM_DUE: | ||
// PWM pins: 6, 7, 8, 9 | ||
// Timer pins: 2-5, 10-13. | ||
// pin2: TC0_CHA0, pin3: TC2_CHA7, pin4: TC2_CHB6, pin5: TC2_CHA6 | ||
// pin 10: TC2_CHB7, pin11: TC2_CHA8, pin12: TC2_CHB8, pin13: TC0_CHB0 | ||
|
||
#if USING_TIMER | ||
#define STEP_PIN 5 | ||
#else | ||
#define STEP_PIN 6 | ||
#endif | ||
|
||
SAMDUE_PWM* stepper; | ||
|
||
#define DIR_PIN 9 | ||
|
||
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 PWM_StepperControl on ")); | ||
Serial.println(BOARD_NAME); | ||
Serial.println(SAMDUE_PWM_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 SAMDUE_PWM(STEP_PIN, 500, 0); | ||
} | ||
|
||
void loop() | ||
{ | ||
setSpeed(1000); | ||
delay(3000); | ||
|
||
// Stop before reversing | ||
setSpeed(0); | ||
delay(3000); | ||
|
||
// Reversing | ||
setSpeed(-500); | ||
delay(3000); | ||
|
||
// Stop before reversing | ||
setSpeed(0); | ||
delay(3000); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
name=SAMDUE_PWM | ||
version=1.0.0 | ||
version=1.0.1 | ||
author=Khoi Hoang <[email protected]> | ||
maintainer=Khoi Hoang <[email protected]> | ||
sentence=This library enables you to use Hardware-based PWM channels on SAMDUE boards to create and output PWM to pins. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters