Skip to content

Instantly share code, notes, and snippets.

@jcreager
Last active September 13, 2020 18:58
Show Gist options
  • Save jcreager/2cdf340e1ff452107bb7ce8beb1e849d to your computer and use it in GitHub Desktop.
Save jcreager/2cdf340e1ff452107bb7ce8beb1e849d to your computer and use it in GitHub Desktop.
hbridge.fs
-hbridge
marker -hbridge
: defpin:
create
c, c,
does>
dup c@
swap 1+ c@
;
: high mset ;
: low mclr ;
: output 1- high ;
: input 1- low ;
\ Digital I/O Registers
36 constant ddrb
37 constant portb
41 constant pind
42 constant ddrd
43 constant portd
\ PWM Registers
128 constant tccr1a
129 constant tccr1b
134 constant icr1
136 constant ocr1a
\ Set the memory context to flash to persist
\ pin definitions between restarts
flash
\ https://arduino-forth.com/article/arduino_comprendreConnecteurs
portd $0080 defpin: ctl1 \ bit7
portd $0010 defpin: ctl2 \ bit4
portb %00000010 defpin: enable \ bit1/oc1a
\ Return memory context to ram
ram
: init.ports ( --- )
ctl1 output
ctl2 output
enable output
%10100000 tccr1a c!
%00010010 tccr1b c!
$4e20 icr1 !
;
: power ( n - ) ocr1a ! ;
: c-clockwise ( --- )
ctl1 high
ctl2 low
;
: clockwise ( --- )
ctl1 low
ctl2 high
;
: stop ( --- )
ctl1 low
ctl2 low
;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment