Menu

A Hanging program does not Print at all

jeff
2021-07-07
2021-07-16
  • jeff

    jeff - 2021-07-07

    I wonder if it would be possible for you to have a quick look at this short program as attached for the beginnings of a Power meter and see if there is any reason for this program to hang....Many Thanks

     
  • Anobium

    Anobium - 2021-07-07

    Sure... can you define hanging? during compiling or when testing the code on real silicon?

     
  • Anobium

    Anobium - 2021-07-07

    Sure... can you define hanging? during compiling or when testing the code on real silicon?

     
  • Anobium

    Anobium - 2021-07-08

    You have bitaliases and constants mixed up.

    Old code with comments

     Dim P1v as BIT    'dim a BIT... not sure why
     Dim P2i as BIT    'dim a BIT... not sure why
     ...
     Dir PortA.3 in     'set direction
     Dir PortA.2 in     'set direction
     dir PortE.3 in     'set direction
     P1v=PortA.3     'set p1v to the state of the port as this point
     P2i=PortA.2     'set p2i to the state of the port as this point
    
      Do Until P1v = 0  'test p1v.. never changes..
      Loop
      Do Until P1v = 1 'test p1v.. never changes..
      Loop
      Do Until P2i = 1 'test p2i.. never changes..
      aa =aa+ 1
      Loop
    

    P1V, p2i were dim'ed as bits, and then you set that bit to the state of a port.

    New code

     #Define P1v PortA.3
     #Define P2i PortA.2
     Dir P1v in
     Dir p2i in
    

    p1v and p2i are constants addressing the two ports, then, using these constants set the port DIRection, then

      Do Until P1v = 0
      Loop
      Do Until P1v = 1
      Loop
      Do Until P2i = 1
      aa =aa+ 1
      Loop
    
     

    Last edit: Anobium 2021-07-08
  • Anobium

    Anobium - 2021-07-08

    Also,

    ~~~
    Do Until P2i = 1
    aa =aa+ 1
    Loop

    If P2i never become high ( =1 ) this will next exit the loop.
    
    Then.. if P2i becomes high.. the chances of AA =0 is 1 in 256.. so, I am not sure what the AA counter does but I would look at that logic but I do not know what the intent is ... so, you nay decide to ignore this.
    
    ----
    
    To make code smaller... add
    

    DEFINE USE_Timer0 false

    DEFINE USE_Timer1 true

    DEFINE USE_Timer2 false

    DEFINE USE_Timer3 false

    DEFINE USE_Timer4 false

    DEFINE USE_Timer5 false

    DEFINE USE_Timer6 false

    ----
    
    And, you may need to change the the PORT to LAT as follows.  In my Simulator I had to change but PORT may work on real silicon.
    

    #Define P1v LATA.3
    #Define P2i LATA.2
    ~~~

    :-)

     
  • William Roth

    William Roth - 2021-07-09

    I see that Debug = ON in the config settings. This should be OFF for normal operation.

    Bill

     
  • jeff

    jeff - 2021-07-11

    Thanks for your comment BILL.
    what i am going to try is
    ANSELA.2=0
    ANSELA.3=0
    to enable the digital input buffer on pins RA2 and RA3 these pins default=1 to enable ADC
    Since by default ADON=0 for disable ADC
    PMD2.ADCMD=0 to Disable ADC module .
    Can you please tell me what amplitude in Volts RA6 FOSC/4 subject to INT107 should be .Any reason why I am not getting 5Vp-p.I am getting +_100mV

     
  • William Roth

    William Roth - 2021-07-11

    The amplitude of clockout on RA6 will vary, depending upon the frequency. The higher the system clock, the lower the amplitude. 100mv is just about right for FOSC =64 Mhz.

    A guideline:

    FOSC=64      16Mhz @ 600mv
    FOSC=32      8Mhz @ 3.3Vp-p
    FOSC=16      4Mhz @ 5.0Vp-p
    FOSC=8       2Mhz @ 5.0Vp-p
    

    It is not necessary change the ANSELA bits as these are already set to the proper default values via "Initsys". Initsys is a subroutine that runs when the chip is started or reset. These setting can viewed by opening the ASM file ( after compiling your code). PMD2 defaults to 0 at POR. and remains at 0 unless intentionally disabled.

    My questions are:

    1) Why do you think you need to change these registers?
    2) What is the actual issue?

     

    Last edit: William Roth 2021-07-11
    • Anobium

      Anobium - 2021-07-12

      Did Jeff try the revised program I posted? As the use of constants and bits was all messed up?

      See this post. https://sourceforge.net/p/gcbasic/discussion/579125/thread/ac3ccb1c84/#5db0

       
  • William Roth

    William Roth - 2021-07-13

    Jeff's latest code attached here - No explanation by Jeff as to why it was posted.

    @Jeff

    If you need help please describe the problem. Simply posting code tells us very little.

    Also, I asked you two questions in my post above but you seemed to ignore them. If you want good help it is important to provide feedback to those taking the time to help.

    William

     

    Last edit: William Roth 2021-07-13
  • jeff

    jeff - 2021-07-13

    Thank you for your comments Mr Roth. What I found was that the 1st program I posted was hanging , after being verified as correctly programmed, when I ran the chip wired to the LCD Nothing printed.wrt the Print(s) LCD at the end of the program and I have another program which prints when tested which even has #CONFIG DEBUG=ON What I suspected was that ANSELA.2 and ANSELA.3 were at their default value of high disabling the digital input buffer.Ignorance of the procedure you mentioned above wrt to the ASM file. So I have included the 2 statements ANSELA.2=0 ANSELA.3=0 to enable the dig input buffer on RA2 and RA3.
    So I sent you the new short program again for which i figured that an expert like you could glance and see if there were any mistakes without a problem.There are a few comments at the top to describe the action.Anything outstanding in respect of a glance and a mistake here in the new short program?
    If ANSELA.2 and ANSELA.3 have been cleared as you say they have then I really have a problem.
    Thanks very much for your help much appreciated .

     
  • William Roth

    William Roth - 2021-07-16

    @Jeff

    You still have not told us what the actual problem is given the the latest code.

    Does the program still "hang"?

    Does the LCD Display initialize and correctly display characters? Yes or No?
    Most LCD displays require 5.0V. A few require 3.3V
    What LCD Display are you using . Brand/ Model
    Why are you using LCD RW ? Do you need to read the LCD memory ?

    Why did you set the LCD Pin Directions with DIR PORTC OUT ( this is done automatically via the LCD library )

    Why do you have CLKOUT enabled on RA6 with #Config INTIO7 ?
    Why have you set PORTE. 3 as an input ?

    It seems to me that you have made a lot of incorrect assumptions that have lead to unnecessary code.

    If it were me I would start from scratch and first get the LCD display working
    with minimal code. Then, confident that the the LCD is working correctly, add in
    sections of code one at a time, verifying as you go.

    For Reference: When a GCB program starts. ALL ANSEL registers are Cleared to 0 and ALL Pins are set as digital inputs. This is the real default.

    So first tell me does the LCD Display work? Yes or No?

     

    Last edit: William Roth 2021-07-16
  • jeff

    jeff - 2021-07-16

    Thanks for your time and consideration. Good news is that the new program works.
    Many thanks to Mr Venn too. Enjoy the weekend.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.