implement MOSFET as logic level shifter

This commit is contained in:
nek0 2021-01-07 21:21:05 +01:00
parent d002253a53
commit 71adba0a3e
13 changed files with 2073 additions and 1834 deletions

5
code/Pentasquare/.gitignore vendored Normal file
View file

@ -0,0 +1,5 @@
.pio
.vscode/.browse.c_cpp.db*
.vscode/c_cpp_properties.json
.vscode/launch.json
.vscode/ipch

View file

@ -0,0 +1,67 @@
# Continuous Integration (CI) is the practice, in software
# engineering, of merging all developer working copies with a shared mainline
# several times a day < https://docs.platformio.org/page/ci/index.html >
#
# Documentation:
#
# * Travis CI Embedded Builds with PlatformIO
# < https://docs.travis-ci.com/user/integration/platformio/ >
#
# * PlatformIO integration with Travis CI
# < https://docs.platformio.org/page/ci/travis.html >
#
# * User Guide for `platformio ci` command
# < https://docs.platformio.org/page/userguide/cmd_ci.html >
#
#
# Please choose one of the following templates (proposed below) and uncomment
# it (remove "# " before each line) or use own configuration according to the
# Travis CI documentation (see above).
#
#
# Template #1: General project. Test it using existing `platformio.ini`.
#
# language: python
# python:
# - "2.7"
#
# sudo: false
# cache:
# directories:
# - "~/.platformio"
#
# install:
# - pip install -U platformio
# - platformio update
#
# script:
# - platformio run
#
# Template #2: The project is intended to be used as a library with examples.
#
# language: python
# python:
# - "2.7"
#
# sudo: false
# cache:
# directories:
# - "~/.platformio"
#
# env:
# - PLATFORMIO_CI_SRC=path/to/test/file.c
# - PLATFORMIO_CI_SRC=examples/file.ino
# - PLATFORMIO_CI_SRC=path/to/test/directory
#
# install:
# - pip install -U platformio
# - platformio update
#
# script:
# - platformio ci --lib="." --board=ID_1 --board=ID_2 --board=ID_N

View file

@ -0,0 +1,7 @@
{
// See http://go.microsoft.com/fwlink/?LinkId=827846
// for the documentation about the extensions.json format
"recommendations": [
"platformio.platformio-ide"
]
}

View file

@ -0,0 +1,39 @@
This directory is intended for project header files.
A header file is a file containing C declarations and macro definitions
to be shared between several project source files. You request the use of a
header file in your project source file (C, C++, etc) located in `src` folder
by including it, with the C preprocessing directive `#include'.
```src/main.c
#include "header.h"
int main (void)
{
...
}
```
Including a header file produces the same results as copying the header file
into each source file that needs it. Such copying would be time-consuming
and error-prone. With a header file, the related declarations appear
in only one place. If they need to be changed, they can be changed in one
place, and programs that include the header file will automatically use the
new version when next recompiled. The header file eliminates the labor of
finding and changing all the copies as well as the risk that a failure to
find one copy will result in inconsistencies within a program.
In C, the usual convention is to give header files names that end with `.h'.
It is most portable to use only letters, digits, dashes, and underscores in
header file names, and at most one dot.
Read more about using header files in official GCC documentation:
* Include Syntax
* Include Operation
* Once-Only Headers
* Computed Includes
https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html

View file

@ -0,0 +1,46 @@
This directory is intended for project specific (private) libraries.
PlatformIO will compile them to static libraries and link into executable file.
The source code of each library should be placed in a an own separate directory
("lib/your_library_name/[here are source files]").
For example, see a structure of the following two libraries `Foo` and `Bar`:
|--lib
| |
| |--Bar
| | |--docs
| | |--examples
| | |--src
| | |- Bar.c
| | |- Bar.h
| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html
| |
| |--Foo
| | |- Foo.c
| | |- Foo.h
| |
| |- README --> THIS FILE
|
|- platformio.ini
|--src
|- main.c
and a contents of `src/main.c`:
```
#include <Foo.h>
#include <Bar.h>
int main (void)
{
...
}
```
PlatformIO Library Dependency Finder will find automatically dependent
libraries scanning project source files.
More information about PlatformIO Library Dependency Finder
- https://docs.platformio.org/page/librarymanager/ldf.html

View file

@ -0,0 +1,15 @@
; PlatformIO Project Configuration File
;
; Build options: build flags, source filter
; Upload options: custom upload port, speed and extra flags
; Library options: dependencies, extra library storages
; Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html
[env:esp32dev]
platform = espressif32
board = esp32dev
framework = arduino
monitor_speed = 115200

View file

@ -0,0 +1,112 @@
#include <Arduino.h>
#include <FastLED.h>
#define LED_TYPE WS2812B
#define COLOR_ORDER RGB
#define NUM_LEDS 100
#define PIN 32
#define BRIGHTNESS 30
#define FPS 120
#define NUM_PATTERNS 4
CRGB leds[NUM_LEDS];
int posx, posy, dx, dy, current_pattern;
typedef void (*PatternList[])();
uint8_t hue = 0;
void confetti() {
fadeToBlackBy(leds, NUM_LEDS, 10);
int pos = random16(NUM_LEDS);
leds[pos] += CHSV(hue + random8(64), 200, 255);
}
void setup_pong() {
posx = random(0, 9);
posy = random(0, 10);
dx = random(0, 1);
if (dx == 0) {
dx = -1;
}
dy = random(0, 1);
if (dy == 0) {
dy = -1;
}
}
void pong() {
int nposx = posx + dx;
if (nposx < 0 || nposx > 9) {
dx = dx * -1;
nposx = posx + dx;
}
posx = nposx;
int nposy = posy + dy;
if (nposy < 0 || nposy > 10) {
dy = dy * -1;
nposy = posy + dy;
}
posy = nposy;
fadeToBlackBy(leds, NUM_LEDS, 10);
if (posx < 10 && posy < 10) {
leds[(posy * 10) + posx] += CHSV(hue, 200, 255);
}
}
void rainbow()
{
// FastLED's built-in rainbow generator
fill_rainbow(leds, NUM_LEDS, hue, 7);
}
void addGlitter( fract8 chanceOfGlitter)
{
if( random8() < chanceOfGlitter) {
leds[ random16(NUM_LEDS) ] += CRGB::White;
}
}
void raindbowWithGlitter() {
rainbow();
addGlitter(80);
}
PatternList patterns = {
confetti,
pong,
rainbow,
raindbowWithGlitter
};
void nextPattern(){
current_pattern = (current_pattern + 1) % NUM_PATTERNS;
}
void setup() {
FastLED.addLeds<LED_TYPE, PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
FastLED.setBrightness(BRIGHTNESS);
FastLED.showColor(CRGB(0, 0, 0));
setup_pong();
}
void loop() {
//confetti();
//pong();
patterns[current_pattern]();
FastLED.show();
FastLED.delay(1000/FPS * 2);
EVERY_N_MILLISECONDS(20) {hue++;}
EVERY_N_SECONDS(10) {nextPattern();}
}

View file

@ -0,0 +1,11 @@
This directory is intended for PIO Unit Testing and project tests.
Unit Testing is a software testing method by which individual units of
source code, sets of one or more MCU program modules together with associated
control data, usage procedures, and operating procedures, are tested to
determine whether they are fit for use. Unit testing finds problems early
in the development cycle.
More information about PIO Unit Testing:
- https://docs.platformio.org/page/plus/unit-testing.html

View file

@ -214,27 +214,35 @@ X VI 3 -300 0 100 R 50 50 1 1 W
ENDDRAW
ENDDEF
#
# Transistor_BJT_PZT2222A
# Transistor_FET_BS170F
#
DEF Transistor_BJT_PZT2222A Q 0 0 Y N 1 F N
DEF Transistor_FET_BS170F Q 0 20 Y N 1 F N
F0 "Q" 200 75 50 H V L CNN
F1 "Transistor_BJT_PZT2222A" 200 0 50 H V L CNN
F2 "Package_TO_SOT_SMD:SOT-223-3_TabPin2" 200 -75 50 H I L CIN
F1 "Transistor_FET_BS170F" 200 0 50 H V L CNN
F2 "Package_TO_SOT_SMD:SOT-23" 200 -75 50 H I L CIN
F3 "" 0 0 50 H I L CNN
ALIAS 2N7002 2N7002E 2N7002H 2N7002K BS170F BS870 BSN20 BSS123 BSS127S DMG2302U DMG3402L DMG3404L DMG3406L DMG3414U DMG3418L DMN10H220L DMN10H700S DMN13H750S DMN2041L DMN2050L DMN2056U DMN2058U DMN2075U DMN2230U DMN24H11DS DMN24H3D5L DMN3042L DMN3051L DMN30H4D0L DMN3110S DMN3150L DMN3300U DMN3404L DMN6075S DMN6140L DMN67D7L DMN67D8L MMBF170 VN10LF ZVN3306F ZVN3310F ZVN3320F ZVN4106F ZXM61N02F ZXM61N03F ZXMN10A07F ZXMN2A01F ZXMN2A14F ZXMN2B01F ZXMN2B14FH ZXMN2F30FH ZXMN2F34FH ZXMN3A01F ZXMN3A14F ZXMN3B01F ZXMN3B14F ZXMN3F30FH ZXMN6A07F IRLML0030 IRLML2060 TSM2302CX AO3400A
$FPLIST
SOT?223*
SOT?23*
$ENDFPLIST
DRAW
C 50 0 111 0 1 10 N
P 2 0 1 0 0 0 25 0 N
P 2 0 1 0 100 -100 25 -25 N
P 2 0 1 0 100 100 25 25 N
P 3 0 1 20 25 75 25 -75 25 -75 N
P 3 0 1 0 90 -90 70 -70 70 -70 N
P 5 0 1 0 45 -65 65 -45 85 -85 45 -65 45 -65 F
X B 1 -200 0 200 R 50 50 1 1 I
X C 2 100 200 100 D 50 50 1 1 P
X E 3 100 -200 100 U 50 50 1 1 P
C 65 0 110 0 1 10 N
C 100 -70 10 0 1 0 F
C 100 70 10 0 1 0 F
P 2 0 1 0 10 0 -100 0 N
P 2 0 1 10 10 75 10 -75 N
P 2 0 1 10 30 -50 30 -90 N
P 2 0 1 10 30 20 30 -20 N
P 2 0 1 10 30 90 30 50 N
P 2 0 1 0 100 100 100 70 N
P 3 0 1 0 100 -100 100 0 30 0 N
P 4 0 1 0 30 -70 130 -70 130 70 30 70 N
P 4 0 1 0 40 0 80 15 80 -15 40 0 F
P 4 0 1 0 110 20 115 15 145 15 150 10 N
P 4 0 1 0 130 15 115 -10 145 -10 130 15 N
X G 1 -200 0 100 R 50 50 1 1 I
X S 2 100 -200 100 U 50 50 1 1 P
X D 3 100 200 100 D 50 50 1 1 P
ENDDRAW
ENDDEF
#

View file

@ -1,11 +1,11 @@
"Id";"Designator";"Package";"Quantity";"Designation";"Supplier and ref";
1;"R5";"R_0603_1608Metric_Pad1.05x0.95mm_HandSolder";1;"2.2k";;;
2;"R4";"R_0603_1608Metric_Pad1.05x0.95mm_HandSolder";1;"6.8k";;;
3;"Q1";"SOT-223";1;"PZT2222A";;;
4;"R2";"R_0603_1608Metric_Pad1.05x0.95mm_HandSolder";1;"470";;;
5;"R3";"R_0603_1608Metric_Pad1.05x0.95mm_HandSolder";1;"1k";;;
6;"J2";"BarrelJack_Horizontal";1;"Barrel_Jack_Switch";;;
7;"U2";"SOT-223-3_TabPin2";1;"AMS1117-3.3";;;
"ID";"Bezeichner";"Gehäuse";"Stückzahl";"Bezeichnung";"Anbieter und Referenz";
1;"U2";"SOT-223";1;"LM1117-3.3";;;
2;"R5";"R_0603_1608Metric_Pad1.05x0.95mm_HandSolder";1;"2.2k";;;
3;"R4";"R_0603_1608Metric_Pad1.05x0.95mm_HandSolder";1;"6.8k";;;
4;"Q1";"SOT-223";1;"PZT2222A";;;
5;"R2";"R_0603_1608Metric_Pad1.05x0.95mm_HandSolder";1;"470";;;
6;"R3";"R_0603_1608Metric_Pad1.05x0.95mm_HandSolder";1;"1k";;;
7;"J2";"BarrelJack_Horizontal";1;"Barrel_Jack_Switch";;;
8;"C4";"CP_Elec_8x10";1;"1m";;;
9;"C2,C1";"C_0603_1608Metric_Pad1.05x0.95mm_HandSolder";2;"100n";;;
10;"C3";"C_1206_3216Metric_Pad1.42x1.75mm_HandSolder";1;"10u";;;

Can't render this file because it has a wrong number of fields in line 2.

File diff suppressed because it is too large Load diff

View file

@ -2,7 +2,7 @@
(general
(thickness 1.6)
(drawings 11)
(drawings 13)
(tracks 452)
(zones 0)
(modules 115)
@ -5863,6 +5863,8 @@
)
)
(gr_line (start 127.28 206.37) (end 124.53 202.67) (layer B.SilkS) (width 0.15))
(gr_line (start 154.83 206.64) (end 152.29 202.51) (layer B.SilkS) (width 0.15))
(gr_text "Design by: nek0 <nek0@nek0.eu>" (at 147.09 204.61) (layer B.SilkS)
(effects (font (size 8 5) (thickness 0.15)) (justify mirror))
)

View file

@ -217,17 +217,6 @@ F 3 "~" H 10350 1350 50 0001 C CNN
1 0 0 -1
$EndComp
$Comp
L Device:R R2
U 1 1 5B6229BA
P 4600 2700
F 0 "R2" V 4393 2700 50 0000 C CNN
F 1 "470" V 4484 2700 50 0000 C CNN
F 2 "Resistor_SMD:R_0603_1608Metric_Pad1.05x0.95mm_HandSolder" V 4530 2700 50 0001 C CNN
F 3 "~" H 4600 2700 50 0001 C CNN
1 4600 2700
0 1 1 0
$EndComp
$Comp
L power:+5V #PWR0202
U 1 1 5B622BDC
P 10350 1200
@ -436,7 +425,7 @@ RTS
Wire Wire Line
4950 2150 5150 2150
Connection ~ 5150 2150
Text Label 4200 2700 0 50 ~ 0
Text Label 4750 2700 2 50 ~ 0
DATA
Text Label 2100 2050 0 50 ~ 0
DATA
@ -459,8 +448,6 @@ $EndComp
Wire Wire Line
10100 1500 10350 1500
Connection ~ 10350 1500
Wire Wire Line
4450 2700 4200 2700
$Comp
L power:+5V #PWR0211
U 1 1 5B64C5A1
@ -561,25 +548,14 @@ F 3 "~" H 3700 5200 50 0001 C CNN
0 1 1 0
$EndComp
$Comp
L Transistor_BJT:PZT2222A Q1
U 1 1 5C10106F
P 5200 2600
F 0 "Q1" V 5436 2600 50 0000 C CNN
F 1 "PZT2222A" V 5527 2600 50 0000 C CNN
F 2 "Package_TO_SOT_SMD:SOT-223" H 5400 2525 50 0001 L CIN
F 3 "http://www.fairchildsemi.com/ds/PN/PN2222A.pdf" H 5200 2600 50 0001 L CNN
1 5200 2600
0 -1 1 0
$EndComp
$Comp
L power:+3.3V #PWR0217
U 1 1 5C1137BE
P 5500 2400
F 0 "#PWR0217" H 5500 2250 50 0001 C CNN
F 1 "+3.3V" V 5515 2528 50 0000 L CNN
F 2 "" H 5500 2400 50 0001 C CNN
F 3 "" H 5500 2400 50 0001 C CNN
1 5500 2400
P 5200 2300
F 0 "#PWR0217" H 5200 2150 50 0001 C CNN
F 1 "+3.3V" V 5215 2428 50 0000 L CNN
F 2 "" H 5200 2300 50 0001 C CNN
F 3 "" H 5200 2300 50 0001 C CNN
1 5200 2300
0 1 1 0
$EndComp
$Comp
@ -613,17 +589,6 @@ Wire Wire Line
4850 2700 4750 2700
Wire Wire Line
4850 2700 5000 2700
$Comp
L Device:R R5
U 1 1 5C124915
P 5350 2400
F 0 "R5" V 5143 2400 50 0000 C CNN
F 1 "2.2k" V 5234 2400 50 0000 C CNN
F 2 "Resistor_SMD:R_0603_1608Metric_Pad1.05x0.95mm_HandSolder" V 5280 2400 50 0001 C CNN
F 3 "~" H 5350 2400 50 0001 C CNN
1 5350 2400
0 1 1 0
$EndComp
Wire Wire Line
5700 2700 5400 2700
$Comp
@ -637,4 +602,17 @@ F 3 "http://www.ti.com/lit/ds/symlink/lm1117.pdf" H 10550 2050 50 0001 C CNN
1 10550 2050
1 0 0 -1
$EndComp
$Comp
L Transistor_FET:BS170F Q1
U 1 1 5FF79E4D
P 5200 2600
F 0 "Q1" V 5449 2600 50 0000 C CNN
F 1 "BS170F" V 5540 2600 50 0000 C CNN
F 2 "Package_TO_SOT_SMD:SOT-23" H 5400 2525 50 0001 L CIN
F 3 "http://www.diodes.com/assets/Datasheets/BS170F.pdf" H 5200 2600 50 0001 L CNN
1 5200 2600
0 1 1 0
$EndComp
Wire Wire Line
5200 2300 5200 2400
$EndSCHEMATC