-
Notifications
You must be signed in to change notification settings - Fork 72
Expand file tree
/
Copy pathmic-jammer-rp2040-PWM-v5.ino
More file actions
117 lines (84 loc) · 3.15 KB
/
Copy pathmic-jammer-rp2040-PWM-v5.ino
File metadata and controls
117 lines (84 loc) · 3.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/*
wearable microphone jammer
Version based on original concept & development :
https://github.com/y-x-c/wearable-microphone-jamming
Boards needed :
Arduino Raspberry Pi Pico 2040 - RP2040-ZERO or RP2040-ONE from Waveshare
TPA3116D2 board - audio amplifier module + potentiometer
OR TC4420 + MOSFET IRF4115
Attention : Use Linux based PC and Arduino Pi Pico Earle Philhower Core for compilation
Board Manager link for Arduino :
https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json
CONNECTION EXAMPLE FOR ARDUINO RP2040-ZERO
--------
GP1 PIN OF RP2040-ZERO --> LEFT AUDIO IN + RIGHT AUDIO IN / or INPUT PIN OF TC4420 MOSFET DRIVER
GND --> AUDIO GND
ARDUINO HAS TO BE POWERED FROM 5V THROUGH LM7805 VOLTAGE STABILIZER OR BUCK-DOWN VOLTAGE CONVERTER
TPA3116 HAS TO BE CONNECTED TO 12V AND GND
*/
#include <Arduino.h>
#include "hardware/pwm.h" // Raspberry PICO SDK library
#include "hardware/clocks.h" // For function clock_get_hz
// pin #1 for GP1 on RP2040-zero board
const int PWM_PIN = 1;
uint slice_num;
uint channel;
// function to gracefully reprogram PWM frequency without glitches
void update_frequency_safe(uint32_t freq) {
uint32_t sys_clk = clock_get_hz(clk_sys);
// Calculating wrap to reduce glitches while changing RP2040 PWM frequency
// sys_clk / freq - 1
uint32_t wrap = (sys_clk / freq) - 1;
// This functions are from RP2040 SDK (double buffered)
pwm_set_wrap(slice_num, wrap);
// pwm_set_chan_level(slice_num, channel, (wrap + 1) / 2);
// setting PWM cycle duty to 35% for best result on LC generator
uint16_t level = (uint16_t)((wrap + 1) * 70 / 100);
pwm_set_chan_level(slice_num, channel, level);
}
void setup() {
// initializing RP2040 PWM pin from Pico SDK
gpio_set_function(PWM_PIN, GPIO_FUNC_PWM);
slice_num = pwm_gpio_to_slice_num(PWM_PIN);
channel = pwm_gpio_to_channel(PWM_PIN);
// Configuration of the PWM defaults
pwm_config config = pwm_get_default_config();
// We want maximum precision of PWM we are not dividing the clock here
pwm_config_set_clkdiv(&config, 1.0f);
// Starting PWM with defaults
pwm_init(slice_num, &config, true);
// Starting swipe from 26KHz down
update_frequency_safe(26000);
randomSeed(1234);
}
void loop() {
uint16_t i, j, x, y;
// Swiping 26kHz -> 24kHz
x = random(20, 50);
j = 1;
i = 26000;
while (i >= 24000) {
i = i - j;
update_frequency_safe(i);
// y = random(1, 4);
// j = (j + y) % x;
j = (j + 1) % x;
if (j == 0) j = 1; // safeguard
// you may want to adjust these
delayMicroseconds(140);
}
// swiping up 24kHz -> 26kHz
x = random(20, 50);
j = 1;
i = 24000;
while (i <= 26000) {
i = i + j;
update_frequency_safe(i);
// y = random(1, 4);
// j = (j + y) % x;
j = (j + 1) % x;
if (j == 0) j = 1; // safeguard
// you may want to adjust these
delayMicroseconds(140);
}
}