Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Electric Car Instrumentation

Status
Not open for further replies.

Chappie

New Member
Hi,

I'm currently designing the instrumentation for an electric car i.e. ammeter, voltmeter, motor temp indicator etc. I've chosen a PIC to monitor all analogue I/p's and display the results on several 7-seg disp. However, I'm having trouble using multiple lookup tables for the various I/p's.

First I thought of checking the analogue ch bits and jumping to the relevant subroutine from there...but it isn't working. :confused: Any I/p would be gratefully recieved

I'm using a 16f877A PIC btw.
 
Your question doesn't make much sense?, try posting your code (use the 'code' tags on the 'go advanced' page to surround the code so it formats properly).
 
Sorry. Hope this helps make it a little clearer

Code:
;The ch0 A/D result is displayed as a 8 bit value
;and subsequently converted to BCD 
;Hardware: PICDEMO board.
;
;
;
	LIST P=16F877A
        ERRORLEVEL  -302
;
	include "p16F877A.inc"
;
TEMP    EQU     20h
adif    equ     1
adgo    equ     2
;
ch2     equ     6
ch3     equ     7
ADTABLE equ     20
;
	ORG     0x00
;
;
	goto    start
;
	org     0x04
	goto    service_int     ;interrupt vector
;
;
	org     0x10
start
	movlw   B'00000000'     ;make port b 
	movwf   PORTB          	;all outputs
;	tris    PORTB          	;       /
        BSF     STATUS, RP0     ;Bank1
        MOVWF   TRISB           ;PortB as outputs
        BCF     STATUS, RP0     ;Bank0
;
	call    InitializeAD   
update      
	movf    ADRES,W
	movwf   0               ;save in table
	movlw   ADTABLE         ;chk if ch0
	subwf   FSR,W           ;     /
	btfss   STATUS,Z        ;yes then skip
	goto    NextAd          ;else do next channel
	movf    ADRES,W         ;get a/d value
	call	outputdata    	;call correct lookup table
	movwf   PORTB		;output to port b
NextAd
	call    NextChannel     ;select next channel
	call    SetupDelay      ;set up > = 10uS
	bcf     ADCON0,adif     ;clear flag
	bsf     ADCON0,adgo     ;start new a/d conversion
loop
	btfsc   ADCON0,adif     ;a/d done?
	goto    update          ;yes then update
	goto    loop            ;wait till done
;
service_int
	return                  ;do not enable int
;
;
;InitializeAD, initializes and sets up the A/D hardware.


InitializeAD
	bsf     STATUS,5        ;select Bank1
	movlw   B'00000010'     ;Vref+ is Vdd, Vref- is Vss, AN0-AN3..
	movwf   ADCON1          ;analog inputs
	bcf     STATUS,5        ;select Bank0
	movlw   B'11000001'     ;select:internal RC, ch0, ststus flag off..
	movwf   ADCON0          ;turn on a/d
	movlw   ADTABLE         ;get top of table address
	movwf   FSR             ;load into indirect reg
	clrf    ADRES           ;clr result reg.
	return

;
;NextChannel, selects the next channel to be sampled in a 
;"round-robin" format.

NextChannel
	movlw   0x08            ;get channel offset
	addwf   ADCON0, F       ;add to conf. reg

	bcf     ADCON0,5        ;clear any carry over

;increment pointer to correct a/d result register

	clrf    TEMP
	btfsc   ADCON0,3        ;test lsb of chnl select
	bsf     TEMP,0          ;set if ch1 or ch3
	btfsc   ADCON0,4        ;test msb bit of chnl select
	bsf     TEMP,1          ;set if ch0 or ch2
	movlw   ADTABLE         ;get top of table
	addwf   TEMP,W          ;add with temp
	movwf   FSR             ;allocate new address
	return

;
;This routine is a software delay of 10uS for the a/d setup.
;At 4Mhz clock, the loop takes 3uS, so initialize TEMp with
;a value of 3 to give 9uS, plus the move etc should result in
;a total time of > 10uS.

SetupDelay
	movlw   .3
	movwf   TEMP
SD
	decfsz  TEMP, F
	goto    SD
	return

;

outputdata

I would like to know how I can refer to different lookup tables for AN0-AN3...
 
Last edited:
Simply don't run it in a single loop, read each input in turn, display it as required, then move to the next input and do the same - enclose the complete chain in an overall loop.
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top