Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Forums > Electronic Projects Design/Ideas/Reviews


Electronic Projects Design/Ideas/Reviews Are you building an electronic project or want to? Maybe you need some assistance? Come and submit your electronic questions here and let our experienced members find a solution.

Reply
 
LinkBack Thread Tools Display Modes
Old 25th April 2007, 03:33 PM   (permalink)
Default Electric Car Instrumentation

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. Any I/p would be gratefully recieved

I'm using a 16f877A PIC btw.
Chappie is offline  
Old 25th April 2007, 03:44 PM   (permalink)
Default

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).
__________________
PIC programmer software, and PIC Tutorials at:
http://www.winpicprog.co.uk
Nigel Goodwin is offline  
Old 25th April 2007, 03:51 PM   (permalink)
Default

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 by Chappie; 25th April 2007 at 03:53 PM.
Chappie is offline  
Old 25th April 2007, 04:18 PM   (permalink)
Default

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.
__________________
PIC programmer software, and PIC Tutorials at:
http://www.winpicprog.co.uk
Nigel Goodwin is offline  
Old 29th April 2007, 10:02 AM   (permalink)
Default

And move to an 18F component - much more efficient ...........
picbits is offline  
Old 29th April 2007, 09:15 PM   (permalink)
Default

Quote:
Originally Posted by picbits
And move to an 18F component - much more efficient ...........
But not at all required!.
__________________
PIC programmer software, and PIC Tutorials at:
http://www.winpicprog.co.uk
Nigel Goodwin is offline  
Old 30th April 2007, 08:17 AM   (permalink)
Default

Very true but I'm a convert
picbits is offline  
Old 30th April 2007, 11:47 AM   (permalink)
Default

Quote:
Originally Posted by picbits
Very true but I'm a convert
Do you means nuns live in you?
__________________
PIC programmer software, and PIC Tutorials at:
http://www.winpicprog.co.uk
Nigel Goodwin is offline  
Old 30th April 2007, 06:37 PM   (permalink)
Default

Quote:
Originally Posted by Nigel Goodwin
Do you means nuns live in you?
Lets not make this a habit
Chappie is offline  
Old 30th April 2007, 07:18 PM   (permalink)
Default

Quote:
Originally Posted by Chappie
Lets not make this a habit
Why is it always 'black and white' with you guys

Lefty
Leftyretro is online now  
Old 30th April 2007, 08:30 PM   (permalink)
Default

I set myself up for that one
picbits is offline  
Old 30th April 2007, 11:13 PM   (permalink)
Default

Quote:
Originally Posted by picbits
I set myself up for that one
I just can't believe how long that went on for!
__________________
PIC programmer software, and PIC Tutorials at:
http://www.winpicprog.co.uk
Nigel Goodwin is offline  
Reply

Bookmarks

Thread Tools
Display Modes



Similar Threads
Title Starter Forum Replies Latest
Building an Electric Scooter? Omar.M Electronic Projects Design/Ideas/Reviews 7 26th April 2007 06:24 AM
Simple question about electric motors sram General Electronics Chat 7 12th February 2007 07:49 PM
Looking for a Electric Board Repair Company Slate General Electronics Chat 4 4th January 2007 03:53 PM
Electric fence zachtheterrible General Electronics Chat 6 15th June 2005 05:33 PM
Electric motor as a generator, DC type? Johnson777717 General Electronics Chat 5 23rd June 2004 10:13 PM



All times are GMT. The time now is 04:41 AM.


Electronic Circuits  |  Learning Electronics
Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.

eXTReMe Tracker