-
Notifications
You must be signed in to change notification settings - Fork 72
Expand file tree
/
Copy pathantispam-jammer-H-Bridge-RP2040-PWM-IR2104-IRF4115-v14-dead-tim.ino
More file actions
130 lines (95 loc) · 4.28 KB
/
Copy pathantispam-jammer-H-Bridge-RP2040-PWM-IR2104-IRF4115-v14-dead-tim.ino
File metadata and controls
130 lines (95 loc) · 4.28 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
/*
Wearable microphone jammer - Vowel Formant Modulation Version (Strict 24kHz-26kHz)
Target: RP2040-ZERO / RP2040-ONE
Core: Earle Philhower RP2040 Core
(C) Adam Loboda 2026
version 14 - FM random modulation (sinusoidal wave) for bobble sounds,
chopper style overloading AGC in smartphones
*/
#include <Arduino.h>
#include "hardware/pwm.h"
#include "hardware/clocks.h"
#include "hardware/adc.h"
const int PIN_NORMAL = 0; // GP0
const int PIN_INVERTED = 1; // GP1
uint slice_num;
// Middle of piezzo transducers resonance frequency
const uint32_t BASE_CARRIER = 25000;
// Trackig Sinusoidal modulation signal phase for seamless FM modulation
float fm_phase = 0.0;
// Human speech formants defintiion for [A, E, I, O, U]
const uint16_t formants[] = {730, 530, 270, 570, 300, 1090, 1840, 840, 870};
const int VOWEL_COUNT = 9;
void update_frequency_safe(uint32_t freq) {
uint32_t sys_clk = clock_get_hz(clk_sys);
uint32_t wrap = sys_clk / (2 * freq);
pwm_set_wrap(slice_num, wrap);
// set the PWM duty level
uint32_t level = (wrap / 2.1);
pwm_set_chan_level(slice_num, PWM_CHAN_A, level);
pwm_set_chan_level(slice_num, PWM_CHAN_B, wrap - level);
}
void setup() {
gpio_set_function(PIN_NORMAL, GPIO_FUNC_PWM);
gpio_set_function(PIN_INVERTED, GPIO_FUNC_PWM);
slice_num = pwm_gpio_to_slice_num(PIN_NORMAL);
pwm_config config = pwm_get_default_config();
pwm_config_set_phase_correct(&config, true);
pwm_config_set_output_polarity(&config, false, true);
pwm_config_set_clkdiv(&config, 1.0f);
pwm_init(slice_num, &config, true);
update_frequency_safe(BASE_CARRIER);
// Randomization seed with ADC input
adc_init();
adc_gpio_init(26);
adc_select_input(0); // channel 0 (GP26) as an input
// we take the 2 LSB bits and shift the output 16 times to achieve 32bit random integer
uint32_t seed = 0;
for (int i = 0; i < 16; i++) {
seed = (seed << 2) ^ (adc_read() & 0x03);
delayMicroseconds(100); };
randomSeed(seed);
// randomSeed(1234);
}
void loop() {
unsigned long startMicros, randomfrequencyDurationMicros;
uint16_t randomfrequency ;
// randomization seed with use of ADC input pin 0 - GP26
uint32_t seed = 0;
for (int i = 0; i < 16; i++) {
seed = (seed << 2) ^ (adc_read() & 0x03);
delayMicroseconds(100); };
randomSeed(seed);
// Here we pick a random INFRASOUND frequency for FM modulation
//uint16_t randomfrequency = random(1,25);
randomfrequency = random(20,50);
// Random human speech wovel frequency to trick smartphones DSP
//int vowelIdx = random(0, VOWEL_COUNT);
//uint16_t randomfrequency = formants[vowelIdx];
// Here we pick random time of this frequency duration
// you may play with this range to have better jamming results on phones mic
//unsigned long randomfrequencyDurationMicros = random(3, 7) * 1000;
randomfrequencyDurationMicros = random(1, 10) * 1000;
// We gather starting time in microseconds for the precision of FM modulation
startMicros = micros();
// Delta-time for the loop interval = 0.000040 sec 40 microseconds - has to match delay at the end of loop
const float dt = 0.000040;
while (micros() - startMicros < randomfrequencyDurationMicros) {
// We calculate FM phase increase during this loop cycle for previusly selected modulation frequency
// dPhi = 2 * PI * f * dt
float phase_increment = 6.28 * randomfrequency * dt;
// Accumulating phase value so the FM modulation has no glithces
fm_phase += phase_increment;
// Adjusting phase so it would match range 0 - 2PI
if (fm_phase >= 6.28 ) fm_phase = fm_phase - 6.28;
// FM modulation to create the sound upon bearer piezo frequency
// Weight 1000 adjusted to fit within piezo acceptable frequency
// piezo range is 24000 - 26000 Hz (25000 +/- 1000 Hz)
long fm_offset = (sin(fm_phase) * 3000);
uint32_t current_freq = BASE_CARRIER + fm_offset;
// Update the frequency
update_frequency_safe(current_freq);
// time for 1 PWM cycle - should match value used for phase calculation
delayMicroseconds( dt * 1000000);
}
}