-
Notifications
You must be signed in to change notification settings - Fork 72
Expand file tree
/
Copy pathmic-jammer-rp2040-PWM-v11.ino
More file actions
135 lines (98 loc) · 4.06 KB
/
Copy pathmic-jammer-rp2040-PWM-v11.ino
File metadata and controls
135 lines (98 loc) · 4.06 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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/*
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;
// Duty of PWM cycle for AM modulation
uint16_t duty = 50;
// function to gracefully reprogram PWM frequency without glitches
void update_frequency_safe(uint32_t freq, uint16_t cycle_duty) {
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);
// normally PWM cycle duty 35%-50% should give best result on LC generator
// but setting up to 70% for highest voltage on the coil
// the higher this value is the more DC current is pumped into coil by the MOSFET
// both MOSFET and coil will get hotter
// uint16_t level = (uint16_t)((wrap + 1) * 70 / 100);
//
// adding SLIGTHLY randomized cycle duty in 65-70 percent range
uint16_t level = (uint16_t)((wrap + 1) * cycle_duty / 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(25350, 50);
randomSeed(1234);
}
void loop() {
uint16_t i, j, x, z;
// Swiping 26kHz -> 24kHz
x = random(20, 50);
j = 1;
i = 25350;
while (i >= 24650 ) {
i = i - j;
update_frequency_safe(i, duty);
// FM modulation
j = (j + 1 ) % x;
if (j == 0) j = 1;
// adding random stops to the frequency swing
if ( (i % random(2,10) ) == 0 ) delayMicroseconds(random(5,75));
// adding random duty changes every N frequency
if ( (i % random(2,5) ) == 0 ) duty = random(40,60);
// when delay less than 50usec the jammer becomes audible but jams better
delayMicroseconds(70);
}
// Swiping up 24kHz -> 26kHz
x = random(20, 50);
j = 1;
i = 24650;
while (i <= 25350 ) {
i = i + j;
update_frequency_safe(i, duty);
// FM modulation
j = (j + 1 ) % x;
if (j == 0) j = 1;
// adding random stops to the frequency swing
if ( (i % random(2,10) ) == 0 ) delayMicroseconds(random(5,75));
// adding random duty changes every N frequency
if ( (i % random(2,5) ) == 0 ) duty = random(50,60);
// when delay less than 50usec the jammer becomes audible but jams better
delayMicroseconds(random(35,45));
}
}