;;;; Name: cluck.asd
;;;; Purpose: Common Lisp uControler Clock Calculator
;;;; Programmer: Kevin M. Rosenberg
-;;;; Date Started: March 207
+;;;; Date Started: March 2007
;;;;
;;;; $Id$
;;;;
;;;; SUCH DAMAGE.
;;;; *************************************************************************
-(defpackage cluck
+(defpackage #:cluck
(:use #:cl)
- (:export
+ (:export
#:show-timers
#:show-8-bit-timers
#:show-16-bit-timers
(defvar *f-cpu* 16000000)
(defvar *8-bit-prescalars* '(1 8 64 256))
-
(defvar *10-bit-prescalars* '(1 8 64 256 1024))
(defvar *base-error-zero-baud-clk* (* 9 25 8192)
"Base multiple for multi-megahertz clock frequencies to have
-0% error at common UART baud rates. Value of this base is 1.8432 million.
+0% error at common UART baud rates. Value of this base is 1.8432 million.
Common multiples of this are 2 (3.6864Mhz), 4 (7.3728Mhz), 8 (14745600),
and 10 (18.432MHz)")
(ms-timer-width ms f-cpu *10-bit-prescalars* width)))
(defparameter *baud-rates* '(300 600 1200 2400 4800 9600 14400 19200 28800
- 38400 56000 57600 76800 115200 128000 250000 256000 500000))
+ 38400 56000 57600 76800 115200 128000 250000
+ 256000 500000))
(defun avr-uart-divisors (&optional (f-cpu *f-cpu*) (view-below-percent nil))
"Displays the divisor UBRR and error percent for various baud
rates for F_CPU. UBBR is limited to 12 bits."
(dolist (baud *baud-rates*)
(let* ((ubrr (min 4096
- (round (- (/ f-cpu 16 baud) 1))))
+ (max 0 (round (- (/ f-cpu 16 baud) 1)))))
(ubrr2 (min 4096
- (round (- (/ f-cpu 8 baud) 1))))
+ (max 0 (round (- (/ f-cpu 8 baud) 1)))))
(actual-baud (/ f-cpu 16 (1+ ubrr)))
(actual-baud2 (/ f-cpu 8 (1+ ubrr2)))
(err (* 100 (- (/ actual-baud baud) 1)))
rates for Fcy. BRG is limited to 16 bits."
(dolist (baud *baud-rates*)
(let* ((brg (min 65536
- (max 1 (round (- (/ fcy 16 baud) 1)))))
+ (max 0 (round (- (/ fcy 16 baud) 1)))))
(actual-baud (/ fcy 16 (1+ brg)))
(err (* 100 (- (/ actual-baud baud) 1))))
- (when (or (not view-below-percent)
+ (when (or (not view-below-percent)
(< (abs err) view-below-percent))
(format t "~6D ~4D ~5,1F%~%" baud brg err)))))