Missing something ... But What ????


Closed Thread
Results 1 to 5 of 5

Hybrid 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 " !!!
    *****************************************

  2. #2
    Join Date
    Nov 2005
    Location
    Bombay, India
    Posts
    966


    Did you find this post helpful? Yes | No

    Default Re: Missing something ... But What ????

    I suggest you try this modification. I think it will work.

    Regards
    Jerson

    Code:
    	IF ADCON0.1 = 0 THEN 
    		Nvalue = ADRESH*256 + ADRESL			' read ADC result
    	ELSE
    		GOTO Wait10
    	ENDIF
    	
    	ADCON0.1	= 1								' relaunch conversion
    	
    	Ivalue = (Ivalue*9 + Nvalue )/10			' Rolling average
    	
    	GOSUB Convert
    	
    	IF Dvalue < Mvalue THEN Mvalue = Dvalue		' Memorize Minimum
    	
    Wait10:
    
    ' Prepare value to be displayed

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


    Did you find this post helpful? Yes | No

    Default Re: Missing something ... But What ????

    Hi, Jerson

    Already had implemented Waiting loop while testing ... but conversion occurs while doing something else ... and has much enough time to be completed !
    after that, multiplexing leds doesn't allow dead times ...

    Alain
    ************************************************** ***********************
    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 " !!!
    *****************************************

  4. #4
    Join Date
    Nov 2005
    Location
    Bombay, India
    Posts
    966


    Did you find this post helpful? Yes | No

    Default Re: Missing something ... But What ????

    Hi Alain

    It is not about the conversion. Let me explain what I think could be the problem you see.

    When you are in ModeI=1, you are putting out a bar graph + a dot position. That is what I understand.

    What happens is when you are doing the bar graph, you are rapidly swiping the leds with the dot to enable your eyes to see a bar.

    After that happens, you wish to have another dot that stays on to represent the current reading. This too happens immediately after the bar is displayed; but, it happens after you erase the bar with LATA=0. Now, only the dot persists till the next time you refresh the display for bar and dot. This time between 2 display refreshes is tied to the delay for ADC in Wait1(your code).

    I choose to not wait for ADC, but process it when ready. Therefore the Wait10

    Regards

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


    Did you find this post helpful? Yes | No

    Default Re: Missing something ... But What ????

    Jerson,

    I just commented the rolling average line
    Code:
    Ivalue = (Ivalue*9 + Nvalue )/10			' Rolling average
    replaced it by
    Code:
    Ivalue = Nvalue
    ... and it began to work fine @ first run !!!

    that is somewhat incredible ...

    6 month ago, I wrote a similar program displaying on a couple of 7 segments : everything was fine.
    but I didn't use any average ...

    I do not understand that because the value was initialized with the average calculated just before entering the display loop ...

    Further tests look to show Nvalue = 0 @ first loop ( why ??? we are looping until a conversion result being available ... and it's ages the Pic ADC is stabilised ! ) : value is close to 9/10 Actual value, and then ... minimum value is generally under the minimum, and then not shown !

    that's how it should work ... but not why !

    I'll try to make further tests ...

    Alain
    Last edited by Acetronics2; - 5th November 2012 at 19:48.
    ************************************************** ***********************
    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