Skip to content

Instantly share code, notes, and snippets.

@ivand58
ivand58 / ntc.py
Created May 2, 2022 07:31
NTC Thermistor calculator
import math
def rp(a,b):
"y = R1||R2"
return a*b/float(a+b)
def rr(r,c):
'''R||y = C'''
return r*c/float(r-c)
@ivand58
ivand58 / cnvrt.py
Created March 28, 2021 10:36
parser
#!/usr/bin/env python
import sys
k = 0
try:
buff = ''
while True:
buff += sys.stdin.read(1)
if buff.endswith('\n'):
@ivand58
ivand58 / data.dat
Created March 28, 2021 10:35
DAC table
48 33.5
56 31
64 29
66 28.5
68 28
70 27.5
72 27.5
73 27
74 26.5
75 26.5
@ivand58
ivand58 / random.fs
Created September 1, 2019 17:22
For a simple random number generator running on an embedded CPU we're unlikely to be very concerned with cycle lengths -- a cycle of 2^32-1 is perfectly acceptable. Marsaglia suggests coefficients (13, 17, 5) for a 32-bit generator.
variable seed
7 seed !
: random ( -- x ) \ return a 32-bit random number x
seed @
dup 13 lshift xor
dup 17 rshift xor
dup 5 lshift xor
dup seed !
;
@ivand58
ivand58 / hexdump.fs
Created August 27, 2019 18:34
A hexdump with Extended Linear Address record for images > 64kB
$FF variable hex.empty \ needs to be variable, some flash is zero when empty
: hexd64k ( n -- )
\ STM32F103x8: Complete image with Dictionary: $FFFF $0000
dup
$FFFF + swap
do
\ Check if this line is entirely empty:
0 \ Not worthy to print
@ivand58
ivand58 / stepmot.fs
Created June 25, 2019 19:31
stepper motor control demo
\ stepper motor 5 wires connected to pb12..pb15 @ bluepill stm32f103 ,
\ tested at mecrisp-stellaris 2.5.0
\ port B base addr
$40010C00 constant GPIOB
GPIOB 4 + constant GPIOB_CRH
GPIOB $10 + constant GPIOB_BSRR
\ init pb12..pb15 omode-pp, all coils to gnd
: sminit ( -- )
$F0000000 ( clr b12-b15 )
@ivand58
ivand58 / gen-cscope.sh
Created June 9, 2019 18:23
generates input for cscope with special treatment of the links
# Write only the files which are NOT symlinks
find `pwd` \( \( -iname "*.c" -o -iname "*.cpp" -o -iname "*.cc" -o -iname "*.h" \) -and \( -not -type l \) \) -print > cscope.files
# Add the target of the symlink for all files matching the right extension, and are symlinks
find `pwd` \( \( -iname "*.c" -o -iname "*.cpp" -o -iname "*.cc" -o -iname "*.h" \) -and -type l \) -exec readlink -f {} \; >> cscope.files
@ivand58
ivand58 / notes.sh
Last active March 17, 2019 08:48
BMP on blue pill
# get submodules by cmake
make
# go to the code
cd src
# if needed - reduce the supported targets
# - search for PROBE
vim target/cortexm.c
# fix the voltage:
vim platforms/stlink/platform.c
# build
@ivand58
ivand58 / deref.fs
Created March 9, 2019 13:18
deref example in Forth
0 variable xx
: test 5 0 do i xx @ execute . loop ;
: dec ['] 1- xx ! ;
: inc ['] 1+ xx ! ;
inc test
dec test
@ivand58
ivand58 / genincpaths.sh
Created December 26, 2018 08:43
Generates include paths
for i in $(find -iname '*.h' -exec dirname "{}" \; | sort -u); do printf -- '-I %s\n' $i ;done