SSブログ

ファームウエアクローズループ [jalv2_PIC]

アナログコンパレータ ファームウエアクローズループ AN700の jalv2化

;*********************************************************************
;* Filename: DeltaSig.asm
;*********************************************************************
;* Author: Dan Butler
;* Company: Microchip Technology Inc.
;* Revision: 1.00
;* Date: 02 December 1998
;* Assembled using MPASM V2.20
;*********************************************************************
;* Include Files:
;* p16C622.inc V1.01
;*********************************************************************
;* Provides two functions implementing the Delta Sigma A2D.
;* InitDeltaSigA2D sets up the voltage reference and comparator
;* in the "idle" state.
;* DeltaSigA2D runs the actual conversion. Results provided in
;* result_l and result_h.
;* See An700 figure 2 for external circuitry required.
;*********************************************************************
;* What's changed
;*
;* Date Description of change
;*
;*********************************************************************
-- chip setup
--#include <p16C622.inc>
--include  16C622
--include  16f628a
include 16f648a
--include chipdef_jallib

--cblock
--        result_l
--        result_h
--        counter:2
var byte result_l
var byte result_h
var byte*2 counter
-- const VOLATILE bit  vcc_ch = 1
-- const VOLATILE bit  pump_p = 2
--endc

alias               rp0                   is _rp0
alias               z                     is _z
--alias               c1out                 is cmcon_c1out
--alias               c1out                 is _c1out
--alias               cmcon,c1out             is cmcon_c1out_c1out
--alias               $+1                   is +1
--alias               goto $+1              is goto +1
;
;
;

Procedure InitDeltaSigA2D() is
  assembler
--InitDeltaSigA2D
        bsf status,_rp0
        movlw 0xec
        movwf vrcon
        bcf porta,3 ;set comparator pin to output
--        bcf status,_rp0
        bcf status,rp0
        movlw 0x06 ;set up for 2 analog comparators with common reference
        movwf cmcon
--        return
  end assembler
end procedure

;
; Delta Sigma A2D
; The code below contains a lot of nops and goto next instruction. These
; are necessary to ensure that each pass through the Elop1 takes the same
; amount of time, no matter the path through the code.
;
Procedure DeltaSigA2D() is
assembler
         LOCAL    elop1,comphigh,complow,eat2cycles,endelop1,eat5cycles,exit1
--DeltaSigA2D
        clrf counter
        clrf counter+1
        clrf result_l
        clrf result_h
        movlw 0x03 ; set up for 2 analog comparators with common reference
        movwf cmcon
elop1:
        btfsc cmcon_c1out ; is comparator high or low?
--        btfsc cmcon,c1out ; is comparator high or low?
        goto complow ; go the low route
comphigh:
        nop ; necessary to keep timing even
        bcf porta,3 ; porta.3 = 0
        incfsz result_l,f ; bump counter
        goto eat2cycles ;
        incf result_h,f ;
        goto endelop1 ;
complow:
        bsf porta,3 ; comparator is low
        nop ; necessary to keep timing even
        goto eat2cycles ; same here
eat2cycles:
        goto endelop1 ; eat 2 more cycles
endelop1:
        incfsz counter,f ; count this lap through the elop1.
        goto eat5cycles ;
        incf counter+1,f ;
        movf counter+1,w ;
        andlw 0x04 ; are we done? (we're done when bit2 of
--        btfsc status,_z ; the high order byte overflows to 1).
        btfsc status,z ; the high order byte overflows to 1).
        goto elop1 ;
        goto exit1
eat5cycles:
        goto +1 ; more wasted time to keep the elop1s even
--        goto $+1 ; more wasted time to keep the elop1s even
        nop ;
        goto elop1 ;
exit1:
        movlw 0x06 ; set up for 2 analog comparators with common reference
        movwf cmcon
--        return
end assembler
end procedure
 
--        end
InitDeltaSigA2D()

forever loop

DeltaSigA2D()

end loop

PICのアナログコンパレータ使用例はデルタシグマによる比較適 精度が高く、

また電圧範囲も0-(Vdd-1.5 )と範囲が広いのが特徴です。

AVRでもアナログコンパレータを使ったローコストADコンバータの例があります。

AVR128,AVR400 です。

これらはSW操作とRC時定数の放電による指数関数カーブをアナログ値として捉える試みで、

各所先輩方もWeb上に出されていて、よく目にいたします。

AVRでの特徴は0-2vくらいがコンパレータの動作域であること、1chしか無いこと、

mega168などにおいてはADCマルチプレックスと同じ扱いで多ch化されています。


コメント(1) 

コメント 1

nekonoko

色々載っていました。
http://www.microchip.com/search/searchapp/searchhome.aspx?id=2&q=AN700
by nekonoko (2011-07-09 10:57) 

コメントを書く

お名前:[必須]
URL:[必須]
コメント:
画像認証:
下の画像に表示されている文字を入力してください。

この広告は前回の更新から一定期間経過したブログに表示されています。更新すると自動で解除されます。