Skip to content

Commit e74a53d

Browse files
committed
Move clearIrc() into for loop
- Sometimes the haptic motor driver will throw a fault when increasing the applied power so we will clear the flag using the clearIrc() in the for loop as opposed to waiting to exit the for loop and clearing the flag - adjust Artemis pin definition from PWM0 to a pin value (i.e. pin 2) - add debugging output for the applied power to be consistent - adjust defaults to Artemis as opposed to Teensy
1 parent e78f927 commit e74a53d

File tree

2 files changed

+25
-24
lines changed

2 files changed

+25
-24
lines changed

examples/PWM_Mode_Teensy_Artemis/PWM_Mode_Teensy_Artemis.ino

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ produce a fault and stop functioning.
1919

2020
Haptic_Driver hapDrive;
2121

22-
int pwmPin = 5; // Teensy
23-
//int pwmPin = PWM0; // Artemis
22+
//int pwmPin = 5; // Teensy
23+
int pwmPin = 2; // Artemis
2424
int power = 20;
2525
int event = 0;
2626

@@ -29,9 +29,9 @@ void setup(){
2929
pinMode(pwmPin, OUTPUT);
3030

3131
//When using Teensy***************************************
32-
analogWriteFrequency(pwmPin, 10000); // Set to 10kHz
32+
//analogWriteFrequency(pwmPin, 10000); // Set to 10kHz
3333
//When usign Artemis***************************************
34-
//analogWriteFrameWidth(1200); //Set to 10kHz
34+
analogWriteFrameWidth(1200); //Set to 10kHz
3535

3636
Wire.begin();
3737
Serial.begin(115200);
@@ -59,18 +59,18 @@ void setup(){
5959

6060
void loop(){
6161

62-
// If uploading often the Haptic Driver IC will throw a fault when the PWM
63-
// signal is cut off suddenly without being set into inactive mode. Let's
64-
// clear that error (0x10), just in case.
65-
event = hapDrive.getIrqEvent();
66-
Serial.print("Interrupt: ");
67-
Serial.println(event, HEX);
68-
Serial.print("Clearing event.");
69-
hapDrive.clearIrq(event);
70-
7162
// I found that the Haptic Driver stops responding around 100 for the
7263
// Artemis.
7364
for (int power = 20; power < 255; power++) {
65+
66+
// If uploading often the Haptic Driver IC will throw a fault when the PWM
67+
// signal is cut off suddenly without being set into inactive mode. Let's
68+
// clear that error (0x10), just in case.
69+
event = hapDrive.getIrqEvent();
70+
Serial.print("Interrupt: ");
71+
Serial.println(event, HEX);
72+
Serial.println("Clearing event.");
73+
hapDrive.clearIrq(event);
7474

7575
analogWrite(pwmPin, power);
7676
Serial.print("Applied power: ");

examples/PWM_Mode_Timer1/PWM_Mode_Timer1.ino

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -62,22 +62,23 @@ void setup(){
6262
}
6363

6464
void loop(){
65-
66-
// If uploading often the Haptic Driver IC will throw a fault when the PWM
67-
// signal is cut off suddenly without being set into inactive mode. Let's
68-
// clear that error (0x10), just in case.
69-
event = hapDrive.getIrqEvent();
70-
Serial.print("Interrupt: ");
71-
Serial.println(event, HEX);
72-
Serial.print("Clearing event.");
73-
hapDrive.clearIrq(event);
74-
7565

7666
for (int power = 10; power < 255; power++) {
67+
68+
// If uploading often the Haptic Driver IC will throw a fault when the PWM
69+
// signal is cut off suddenly without being set into inactive mode. Let's
70+
// clear that error (0x10), just in case.
71+
event = hapDrive.getIrqEvent();
72+
Serial.print("Interrupt: ");
73+
Serial.println(event, HEX);
74+
Serial.println("Clearing event.");
75+
hapDrive.clearIrq(event);
7776

7877
Timer1.pwm(pwmPin, power);
78+
Serial.print("Applied power: ");
79+
Serial.println(power);
7980
Serial.print("Vibration value: ");
80-
Serial.println(hapDrive.getVibrate(), HEX);
81+
Serial.println(hapDrive.getVibrate());
8182
delay(100);
8283

8384

0 commit comments

Comments
 (0)