Loading files
This file is pinned to the selected release. Download the original to open it in your design tool.
260934f58This file is pinned to the selected release. Download the original to open it in your design tool.
; square_wave_gen.pio
; Copyright (C) 2021-2022 Timo Kokkonen <tjko@iki.fi>
;
; SPDX-License-Identifier: GPL-3.0-or-later
;
; This file is part of FanPico.
;
; FanPico is free software: you can redistribute it and/or modify
; it under the terms of the GNU General Public License as published by
; the Free Software Foundation, either version 3 of the License, or
; (at your option) any later version.
;
; FanPico is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
; GNU General Public License for more details.
;
; You should have received a copy of the GNU General Public License
; along with FanPico. If not, see <https://www.gnu.org/licenses/>.
;
; Adjustable Square Wave signal generator that reads 'period' from FIFO.
; Output is a square wave (at 50% duty cycle) where length of each pulse
; is 10+2*period clock cycles.
;
; Side-set pin 0 is used for output
.program square_wave_gen
.side_set 1 opt
start:
pull noblock side 0 ; Read 'period from FIFO to OSR and set output low
; ('noblock' causes X to be copied into OSR if FIFO empty)
mov x, osr ; Save 'period' in X
mov y, x ; Copy X to Y (which is used as counter).
jmp !y start ; Steady low output if period is 0
lo_loop:
jmp y-- lo_loop ; Loop until Y hits 0
mov y, x side 1 ; Reset Y back to X and set output high
nop [2] ; Wait 3 cycle to keep both sides same length
hi_loop:
jmp y-- hi_loop ; Loop until Y hits 0
; eof :-)