Skip to content

Commit cf5e78f

Browse files
author
Mark C
committed
numerous changes and fixes and stuff.
1 parent e2847df commit cf5e78f

File tree

1 file changed

+36
-17
lines changed

1 file changed

+36
-17
lines changed

fpga-code/glitch_demo.v

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,39 @@
11
/*
2-
* Copyright 2015 Forest Crossman
2+
* This code is mostly mine - some of it was adapted from here:
3+
* https://github.com/deanjerkovich/avr-glitch-101
4+
*
5+
* But the concept now is different - we want controllable glitches,
6+
* that we can drive through, say, and python script using PySerial.
7+
* This means that we take a value, and then use that (multiplied by
8+
* 512) as our glitch time value
9+
*
10+
* So, yeah - most of this is written/hacked together by me on a Sunday
11+
* afternoon...
12+
* Released under MIT License:
13+
*
14+
* Permission is hereby granted, free of charge, to any person obtaining
15+
* a copy of this software and associated documentation files (the
16+
* "Software"), to deal in the Software without restriction, including
17+
* without limitation the rights to use, copy, modify, merge, publish,
18+
* distribute, sublicense, and/or sell copies of the Software, and to
19+
* permit persons to whom the Software is furnished to do so, subject to
20+
* the following conditions:
321
*
4-
* Licensed under the Apache License, Version 2.0 (the "License");
5-
* you may not use this file except in compliance with the License.
6-
* You may obtain a copy of the License at
7-
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
10-
* Unless required by applicable law or agreed to in writing, software
11-
* distributed under the License is distributed on an "AS IS" BASIS,
12-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
* See the License for the specific language governing permissions and
14-
* limitations under the License.
22+
* The above copyright notice and this permission notice shall be
23+
* included in all copies or substantial portions of the Software.
1524
*
1625
*/
1726

1827
`include "cores/osdvu/uart.v"
1928
`include "pll-72.v"
2029

30+
31+
// These I set and then didn't really use...
32+
// I've left them here as example artefacts in case someone wants
33+
// to use them in some re-implementation... just reference them
34+
// including a preceeding backtick... e.g.
35+
// if (counter == `WAIT_TIME) begin...
36+
// as a quick example line. :-P
2137
`define GLITCH_DURATION 26000
2238
`define GLITCH_MULTIPLIER 100
2339
`define WAIT_TIME 72000000
@@ -36,7 +52,6 @@ module top(
3652
);
3753

3854
assign LED0 = outreg;
39-
//assign LED1 = ~outreg;
4055
assign LED1 = ~outreg;
4156
assign J1_1 = outreg;
4257

@@ -68,7 +83,7 @@ module top(
6883
assign {LED3, LED2} = rx_byte[7:6];
6984

7085
uart #(
71-
.baud_rate(9600), // The baud rate in kilobits/s
86+
.baud_rate(115200), // The baud rate in kilobits/s
7287
.sys_clk_freq(12000000) // The master clock frequency
7388
)
7489
uart0(
@@ -101,8 +116,9 @@ module top(
101116
end
102117
always @(posedge iCE_CLK) begin
103118
// dirty reset of glitch signal if it is set - saves on
104-
// waiting for UART to change mode NB - our other clock is a lot
105-
// faster, so will certainly see this signal
119+
// waiting for UART to change mode
120+
// NB - our other clock is a lot faster, so will certainly
121+
// see this signal most of the time #DirtyHax
106122
if (glitch_signal) begin
107123
glitch_signal <= 0;
108124
end
@@ -126,7 +142,10 @@ module top(
126142
// check if glitch_signal is on, and if yes,
127143
// reset counter and set glitch flag
128144
if (glitch_signal && !glitch) begin
129-
// turns out we don't know the interface register uart_var1...
145+
// turns out we don't know the interface register
146+
// uart_var1... take rx_byte and multiply it by 512 - this
147+
// gives us roughly +7 microsecond increase in glitch time
148+
// for every +1 increase in UART byte value... ish...
130149
var1 <= rx_byte << 8;
131150
glitch <= 1;
132151
counter <= 0;

0 commit comments

Comments
 (0)