Missing something ... But What ????


Results 1 to 5 of 5

Threaded View

  1. #1
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,648

    Default Missing something ... But What ????

    confused:

    Hi,
    I wrote a little Expanded scale Voltmeter program ...

    But I'm loosing my last hair on a little problem !

    Here's the program:

    Code:
    '*******************************************************************************
    'Voltmètre12.bas
    '
    ' R/C Expanded scale Voltmeter 
    ' Pic 12F1840
    ' 12 Multiplexed Leds
    
    ' 2 Display modes :
    ' - Jumper ON is Actual voltage BAR Display
    ' - Jumper OFF is Minimun reached Voltage in BAR Mode, plus Actual Voltage in DOT Mode
    ' ( intended to show Voltage swing under load )
    '*******************************************************************************
    
    ' Defines
    '*******************************************************************************
    DEFINE OSC 32
    'DEFINE 
    
    
    
    ' Config
    '*******************************************************************************
    
    #CONFIG
    
    	__CONFIG	_CONFIG1, _FOSC_INTOSC & _WDTE_ON & _PWRTE_ON & _MCLRE_OFF & _BOREN_ON
    	__CONFIG	_CONFIG2, _PLLEN_ON & _BORV_LO & _LVP_OFF
    
    #ENDCONFIG
    
    OPTION_REG	= %10000001
    WPUA		= %00001000
    OSCCON 		= %11110000					' !!! SCS 1:0 = 00 pour PLL ON !!!
    INTCON 		= 0
    PIE1 		= 0
    T1CON 		= 0
    T1GCON		= 0
    CM1CON0		= 7
    ADCON0		= %00000001
    ADCON1		= %11100011
    FVRCON		= %11010011
    
    LATA 		= 0
    TRISA		= 255
    
    '*******************************************************************************
    ' Aliases
    
    Modeselect 	VAR PORTA.3
    
    '*******************************************************************************
    ' Variables
    
    Nvalue	VAR WORD
    Ivalue	VAR WORD
    
    Mvalue	VAR BYTE
    Dvalue 	VAR BYTE
    Value 	VAR BYTE
    I		VAR BYTE
    
    mode	VAR BYTE
    modeI	VAR BYTE
    
    CLEAR
    
    Mvalue = 12
    '*******************************************************************************
    test:
    
    FOR Value = 1 to 12
    
    	Mode = 0 : ModeI = 0
    	GOSUB Display
    	PAUSE 200
    
    NEXT Value
    
    LATA	=	0
    Dvalue = 0
    
    BUTTON Modeselect,0,255,0,I,0,First				' Display actual Voltage
    ModeI = 1										' IF Jumper ON then Alternate mode
    
    '*******************************************************************************
    First:											' 
    
    ADCON0.1 = 1									'Launch First Conversion
    
    Wait0:
    FOR I = 1 to 16
    
    	IF ADCON0.1 = 0 THEN 
    		Nvalue = ADRESH*256 + ADRESL			' read ADC result
    	ELSE
    		GOTO Wait0
    	ENDIF
    	
    	ADCON0.1	= 1								' relaunch conversion
    	
    	Ivalue = (Ivalue*9 + Nvalue )/10			' First Value for Ivalue
    												' = True value for Mvalue !
    NEXT I
    
    '*******************************************************************************
    Main:
    
    WHILE 1
    
    Wait1:
    	IF ADCON0.1 = 0 THEN 
    		Nvalue = ADRESH*256 + ADRESL			' read ADC result
    	ELSE
    		GOTO Wait1
    	ENDIF
    	
    	ADCON0.1	= 1								' relaunch conversion
    	
    	Ivalue = (Ivalue*9 + Nvalue )/10			' Rolling average
    	
    	GOSUB Convert
    	
    	IF Dvalue < Mvalue THEN Mvalue = Dvalue		' Memorize Minimum
    	
    
    ' Prepare value to be displayed
    	
    	IF ModeI == 1 THEN 	
    		FOR I = 0 to Dvalue						' Bar Display Actual value
    			Value = I
    			GOSUB Display
    		NEXT I
    	
    	ELSE
    		FOR I = 0 to Mvalue						' Bar Display Min Value 
    			Value = I
    			GOSUB Display
    		NEXT I
    
    			Value = Dvalue						' Add Actual Value dot
    			GOSUB Display
    	ENDIF
    
    WEND
    END
    
    '*******************************************************************************
    Display:
    
    LATA = 0										'Prevent Ghosting
    
    LOOKUP Value,[%11111111,%11111001,%11111001,%11101101,%11101101,%11011101,%11011101,_
    			  %11101011,%11101011,%11011011,%11011011,%11001111,%11001111], TRISA
    
    LATA.1	= !!(value == 2)|| (value == 4) || (value == 6)
    LATA.2	= !!(value == 1)|| (value == 8) || (value ==10)
    LATA.4	= !!(value == 3)|| (value == 7) || (value ==12)
    LATA.5	= !!(value == 5)|| (value == 9) || (value ==11)
    
    
    PAUSE 1
    RETURN
    
    '*******************************************************************************
    Convert:										'Convert ADC Counts to LED#
    
    LOOKDOWN2 Ivalue, < [513,526,538,551,563,576,588,601,613,626,638,651,663], Dvalue
    
    '*******************************************************************************
    'Test purpose values set
    'LOOKDOWN2 Ivalue, < [551,563,576,588,601,613,626,638,651,663,676,688,700], Dvalue
    '*******************************************************************************
    RETURN
    END
    
    
    END
    scheme joined.

    Everything could be Ok ...

    BUT

    in Default mode ( jumper OFF ) ... ONLY the Actual voltage is displayed by its dot : the minimum voltage doesn't appear ( the BAR )

    THIS section fails:
    Code:
    	ELSE
    		FOR I = 0 to Mvalue						' Bar Display Min Value 
    			Value = I
    			GOSUB Display
    		NEXT I
    
    			Value = Dvalue						' Add Actual Value dot
    			GOSUB Display
    	ENDIF
    MPLAB SIM doesn't show anything strange, as it shows the BAR is simulated correctly ( timing also OK ...)

    So, ... I do not see what's wrong

    @ Darrel ... 12F1840 not supported by ISIS ... so, no more simulation solution


    Thanks to the one who will see anything ...


    Alain
    Attached Images Attached Images
    Attached Files Attached Files
    Last edited by Acetronics2; - 5th November 2012 at 13:35.
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

Similar Threads

  1. Missing a bit
    By l_gaminde in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 31st August 2009, 18:54
  2. I've got to be missing something
    By Perrin` in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 19th July 2008, 00:27
  3. What am I missing????
    By cphillips82 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 15th July 2008, 14:03
  4. What am I missing here? If..Then
    By elevenscorpions in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 22nd May 2007, 03:06
  5. What am I missing
    By PaulB in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 12th November 2004, 16:15

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts