Hot!Logic Probe Project C Code Help Needed and Free Give Away

Page: 1234 > Showing page 1 of 4
Author
t1d
Junior Member
  • Total Posts : 98
  • Reward points : 0
  • Joined: 2015/01/26 15:49:24
  • Location: 0
  • Status: offline
2018/04/04 11:19:09 (permalink)
0

Logic Probe Project C Code Help Needed and Free Give Away

Re:
PIC12F683
Project: Logic Probe, Dual Logic Level (TTL & CMOS,) Tri-State (Low, Indeterminate, High)
MPLab X V4.15
XC8 v1.45
C Code – Beginner Level
 
I have written the following code, for my Logic Probe Project. It is heavily commented, so I think you can follow the operations. The issue is that the compiler is:
1) Spitting out lots of signed to unsigned conversion errors.
2) Various Makefile errors, that are totally out of my pay grade.
3) Claiming that there is an unidentified symbol, but, when I click on it, I do not get redirected to the offending line of code, i.e., I can’t find it.
 
I have studied on the type conversion standards. Best I can tell, the code author needs to inform the compiler of the result type, for calculations that use variables. And, that certain operands may automatically change the variable type…For example, “<” and “>” promote the variable type.
 
I have tried all sorts of permutations and combinations of adding the new type (Example; (float),) to the computations, but no joy. I am so green, that I don’t know if I am doing the syntax correctly. But, I am also aware that XC8 has a reputation of claiming that there are conversion errors, when there really aren’t any. So, I am wondering if that is the case and I am hunting ghosts.
 
I would appreciate your help with my syntax, to clear the conversion errors, corrections for the makefile errors and instructions, on how to clear the unidentified symbol. Example syntax would be wonderful. After that, I will correct the operations, to make sure the code does what I intend.
 
I already have the PCBs in hand. Just for fun, I will send a completed unit, free of charge, to the person that I think gave the most help, or the break-through tip. This will be subject to my whims, of course, but it should add a little entertainment. Shipping to the Lower 48 States, only.
 
The code is attached.… The server would not allow me to post the code as text... Maybe special characters are the problem? Sorry, I did not use the correct tab conventions.
 
#1

68 Replies Related Threads

    jtemples
    Super Member
    • Total Posts : 11018
    • Reward points : 0
    • Joined: 2004/02/13 12:31:19
    • Location: Southern California
    • Status: offline
    Re: Logic Probe Project C Code Help Needed and Free Give Away 2018/04/04 11:33:18 (permalink)
    +1 (1)
    The signed/unsigned messages are warnings, not errors.
     
    The undefined symbol is clearly pointed out in the compiler ouput:  read_adc().  You call this function but it's not defined in your code.
    #2
    t1d
    Junior Member
    • Total Posts : 98
    • Reward points : 0
    • Joined: 2015/01/26 15:49:24
    • Location: 0
    • Status: offline
    Re: Logic Probe Project C Code Help Needed and Free Give Away 2018/04/04 18:43:06 (permalink)
    0
    Thank you, Mr. Temples, for your help.
     
    I hate that the conversion notices were wild geese. I won't get those hours back.
     
    This cleared the adc notice:
    [/code]
     // ADC Intialization
    void init_adc ();
    ADCON0bits.GO_DONE = 1;  // Initializes A/D Conversion
        while (ADCON0bits.GO_DONE);   // Wait for A/D Conversion to complete
               {
               void (ADRESH) (void);  // Calls ADRESH and returns its value.            
               }
        read_adc = 0;
    [/code]
     
    But, the new build still fails:
    [/code]
    CLEAN SUCCESSFUL (total time: 672ms)
    make -f nbproject/Makefile-default.mk SUBPROJECTS= .build-conf
    make[1]: Entering directory 'C:/Users/Txxx/Desktop/LPF/LPF.X'
    make  -f nbproject/Makefile-default.mk dist/default/production/LPF.X.production.hex
    make[2]: Entering directory 'C:/Users/Txxx/Desktop/LPF/LPF.X'
    "C:\Program Files (x86)\Microchip\xc8\v1.45\bin\xc8.exe" --pass1  --chip=12F683 -Q -G  --double=24 --float=24 --opt=+asm,+asmfile,-speed,+space,-debug,-local --addrqual=ignore --mode=free -P -N255 --warn=-3 --asmlist -DXPRJ_default=default  --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,-osccal,-resetbits,-download,-stackcall,+clib   --output=-mcof,+elf:multilocs --stack=compiled:auto:auto "--errformat=%f:%l: error: (%n) %s" "--warnformat=%f:%l: warning: (%n) %s" "--msgformat=%f:%l: advisory: (%n) %s"    -obuild/default/production/LPFmain.p1  LPFmain.c
    "C:\Program Files (x86)\Microchip\xc8\v1.45\bin\xc8.exe" --pass1  --chip=12F683 -Q -G  --double=24 --float=24 --opt=+asm,+asmfile,-speed,+space,-debug,-local --addrqual=ignore --mode=free -P -N255 --warn=-3 --asmlist -DXPRJ_default=default  --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,-osccal,-resetbits,-download,-stackcall,+clib   --output=-mcof,+elf:multilocs --stack=compiled:auto:auto "--errformat=%f:%l: error: (%n) %s" "--warnformat=%f:%l: warning: (%n) %s" "--msgformat=%f:%l: advisory: (%n) %s"    -obuild/default/production/LPFconfig.p1  LPFconfig.c
    LPFmain.c:90: error: (202) only lvalues can be assigned to or modified
    LPFmain.c:162: warning: (373) implicit signed to unsigned conversion
    LPFmain.c:166: warning: (373) implicit signed to unsigned conversion
    LPFmain.c:167: warning: (373) implicit signed to unsigned conversion
    LPFmain.c:168: warning: (373) implicit signed to unsigned conversion
    LPFmain.c:171: warning: (373) implicit signed to unsigned conversion
    LPFmain.c:184: warning: (373) implicit signed to unsigned conversion
    LPFmain.c:188: warning: (373) implicit signed to unsigned conversion
    LPFmain.c:189: warning: (373) implicit signed to unsigned conversion
    LPFmain.c:207: warning: (373) implicit signed to unsigned conversion
    LPFmain.c:211: warning: (373) implicit signed to unsigned conversion
    LPFmain.c:212: warning: (373) implicit signed to unsigned conversion
    (908) exit status = 1
    make[2]: *** [build/default/production/LPFmain.p1] Error 1
    make[2]: *** Waiting for unfinished jobs....
    nbproject/Makefile-default.mk:114: recipe for target 'build/default/production/LPFmain.p1' failed
    make[1]: *** [.build-conf] Error 2
    make: *** [.build-impl] Error 2
    make[2]: Leaving directory 'C:/Users/Txxx/Desktop/LPF/LPF.X'
    nbproject/Makefile-default.mk:90: recipe for target '.build-conf' failed
    make[1]: Leaving directory 'C:/Users/Txxx/Desktop/LPF/LPF.X'
    nbproject/Makefile-impl.mk:39: recipe for target '.build-impl' failed

    BUILD FAILED (exit value 2, total time: 2s)
    [/code]
     
    Any ideas, on how to clear the makefile errors?
     
    Thank you, so much, for your help. I was becoming discouraged. That takes the fun out of it... Too much like work...
    #3
    qɥb
    Monolothic Member
    • Total Posts : 3332
    • Reward points : 0
    • Joined: 2017/09/09 05:07:30
    • Location: Jupiter
    • Status: offline
    Re: Logic Probe Project C Code Help Needed and Free Give Away 2018/04/04 19:10:02 (permalink)
    +1 (1)
    t1dunn
     ...
    This cleared the adc notice:
    [/code]
     // ADC Intialization
    void init_adc ();
    ADCON0bits.GO_DONE = 1;  // Initializes A/D Conversion
       while (ADCON0bits.GO_DONE);   // Wait for A/D Conversion to complete
              {
              void (ADRESH) (void);  // Calls ADRESH and returns its value.            
              }
       read_adc = 0;
    [/code]

    Your code tags did not work because the "opening tag" should not contain a "/".
    With that corrected, it would look like this:

    // ADC Intialization
    void init_adc ();
    ADCON0bits.GO_DONE = 1;  // Initializes A/D Conversion
       while (ADCON0bits.GO_DONE);   // Wait for A/D Conversion to complete
              {
              void (ADRESH) (void);  // Calls ADRESH and returns its value.            
              }
       read_adc = 0;

     

    LPFmain.c:90: error: (202) only lvalues can be assigned to or modified

    I would assume that the line it is complaining about (line#90) is this one:
       read_adc = 0;

    And I would also assume that "read_adc" is the name of a function, not a variable.
     
    I suspect you are coming from Visual Basic, where a function returns a value by writing to a dummy variable with the same name as the function. C does not work like that.
    Now, "init_adc()" sounds like a function that should initialise the ADC peripheral, so should be called once.
    You have the ADC initialisation code in the body of your main() function.
    The code you attached to post#1 showed a declaration for a function called "init_adc()" inside the body of the main function. That's just plain wrong.
     
    I would suggest what you really want is a function that reads the ADC high byte and returns the result.
    That should look like this:
    unsigned char read_adc (void)
     
    {
        ADCON0bits.GO_DONE = 1;  // Start A/D Conversion
        while (ADCON0bits.GO_DONE);   // Wait for A/D Conversion to complete
     
        return ADRESH;  // Reads the ADRESH register and returns its value.            
    }

    It should placed in your code BEFORE the main function, not inside it.
     
    post edited by qɥb - 2018/04/04 19:12:24

    This forum is mis-configured so it only works correctly if you access it via https protocol.
    The Microchip website links to it using http protocol. Will they ever catch on?
    PicForum "it just works"
    #4
    t1d
    Junior Member
    • Total Posts : 98
    • Reward points : 0
    • Joined: 2015/01/26 15:49:24
    • Location: 0
    • Status: offline
    Re: Logic Probe Project C Code Help Needed and Free Give Away 2018/04/04 19:33:32 (permalink)
    0
    qɥbYour code tags did not work because the "opening tag" should not contain a "/".

    Excellent... But, that difference is not noted, in the forum instructions... Just says [/code,] IIRC.
    qybI suspect you are coming from Visual Basic
    No, just a real beginner, with C.
    qybNow, "init_adc()" sounds like a function that should initialise the ADC peripheral, so should be called once.
    You have the ADC initialisation code in the body of your main() function.
    The code you attached to post#1 showed a declaration for a function called "init_adc()" inside the body of the main function. That's just plain wrong.
    Excellent tutelage.
     
    qybI would suggest what you really want is a function that reads the ADC high byte and returns the result.
    That should look like this:
    unsigned char read_adc (void)
     
     
     
    {
        ADCON0bits.GO_DONE = 1;  // Start A/D Conversion
        while (ADCON0bits.GO_DONE);   // Wait for A/D Conversion to complete
     
     
     
        return ADRESH;  // Reads the ADRESH register and returns its value.            
    }

    It should placed in your code BEFORE the main function, not inside it.
    Thank you so much, for extending your answer, to show how to do it the right way. Beginners, like me, really need this extra step. We can learn, by reverse engineering the correct code, and make immediate progress, with our project, which reduces frustration. Kudos!
     
    I'm off to make corrections. Back, in just a few minutes...
    #5
    t1d
    Junior Member
    • Total Posts : 98
    • Reward points : 0
    • Joined: 2015/01/26 15:49:24
    • Location: 0
    • Status: offline
    Re: Logic Probe Project C Code Help Needed and Free Give Away 2018/04/04 19:44:04 (permalink)
    0
    Woot! (Who knew a retired guy could learn the kid lingo?) The code compiles!
     
    If qyb and Mr. Temples would send me a pm with your mailing addresses, I will ship you a probe, as soon as the project is complete.
     
    I am ever so grateful! Thank you!
    #6
    qɥb
    Monolothic Member
    • Total Posts : 3332
    • Reward points : 0
    • Joined: 2017/09/09 05:07:30
    • Location: Jupiter
    • Status: offline
    Re: Logic Probe Project C Code Help Needed and Free Give Away 2018/04/04 19:48:49 (permalink)
    0
    t1dunn
    Woot! (Who knew a retired guy could learn the kid lingo?) The code compiles!

    I suspect you have a little more work to do before it works though.
     
    I see you're using lots of floating point, with the intention of outputting real voltages later.
    That's your choice, it's making the code lot lot less efficient than it could be if you did it all with integer math.
     

    If qyb and Mr. Temples would send me a pm with your mailing addresses, I will ship you a probe, as soon as the project is complete.

    There's no need, but if you're keen, I know John is in Southern CA.
    I'm not in the US, and I guess you are, so you'd be looking at much higher mailing charges to me ;)
     
     
     

    This forum is mis-configured so it only works correctly if you access it via https protocol.
    The Microchip website links to it using http protocol. Will they ever catch on?
    PicForum "it just works"
    #7
    1and0
    Access is Denied
    • Total Posts : 8525
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: Logic Probe Project C Code Help Needed and Free Give Away 2018/04/04 20:00:55 (permalink)
    0
    qɥb
    I'm not in the US, and I guess you are, so you'd be looking at much higher mailing charges to me ;)

    ... the fifth planet in the sol system ;)
    #8
    qɥb
    Monolothic Member
    • Total Posts : 3332
    • Reward points : 0
    • Joined: 2017/09/09 05:07:30
    • Location: Jupiter
    • Status: offline
    Re: Logic Probe Project C Code Help Needed and Free Give Away 2018/04/04 20:32:06 (permalink)
    0
    Indeed.
    I'm still waiting for the Tesla Roadster to arrive :)

    This forum is mis-configured so it only works correctly if you access it via https protocol.
    The Microchip website links to it using http protocol. Will they ever catch on?
    PicForum "it just works"
    #9
    t1d
    Junior Member
    • Total Posts : 98
    • Reward points : 0
    • Joined: 2015/01/26 15:49:24
    • Location: 0
    • Status: offline
    Re: Logic Probe Project C Code Help Needed and Free Give Away 2018/04/04 20:34:15 (permalink)
    0
    qɥb
    I see you're using lots of floating point, with the intention of outputting real voltages later.
    That's your choice, it's making the code lot lot less efficient than it could be if you did it all with integer math.
    Outputting the voltages is not the reason for float. All of the voltages are not whole numbers. So, I thought that float was required. I'm not too worried about efficiency, if it works... If the code is not too big, for the chip...
    qɥbI'm not in the US, and I guess you are, so you'd be looking at much higher mailing charges to me ;)
    Well then, my sincere appreciation.
    #10
    qɥb
    Monolothic Member
    • Total Posts : 3332
    • Reward points : 0
    • Joined: 2017/09/09 05:07:30
    • Location: Jupiter
    • Status: offline
    Re: Logic Probe Project C Code Help Needed and Free Give Away 2018/04/04 20:38:11 (permalink)
    +1 (1)
    t1dunn
    ...
    Outputting the voltages is not the reason for float. All of the voltages are not whole numbers. So, I thought that float was required.

    Just consider for a moment, expressing all your voltages in millivolts rather than volts. :)
     

    This forum is mis-configured so it only works correctly if you access it via https protocol.
    The Microchip website links to it using http protocol. Will they ever catch on?
    PicForum "it just works"
    #11
    t1d
    Junior Member
    • Total Posts : 98
    • Reward points : 0
    • Joined: 2015/01/26 15:49:24
    • Location: 0
    • Status: offline
    Re: Logic Probe Project C Code Help Needed and Free Give Away 2018/04/04 20:59:16 (permalink)
    0
    qɥbJust consider for a moment, expressing all your voltages in millivolts rather than volts. :)
    Well, lets look at an example... A typical TTL logic system uses 0.80v, as the low state threshold, and 2.2v, as the high state threshold. So, all comparisons required floating decimal math... And, that requires float variables. Correct? Maybe I don't understand the use of intergers and floats?
     
     
    A voltage divider network is required on the front end, to reduce high state CMOS voltages (can be greater than 5v,) to a level that the chip can tolerate. The software multiples the sampled voltage back up to the actual voltage, to emphasize the difference between the sampled voltage and the reference voltage. Hopefully, this will improve performance/accuracy.
     
    Any suggestions are welcome.
    #12
    jtemples
    Super Member
    • Total Posts : 11018
    • Reward points : 0
    • Joined: 2004/02/13 12:31:19
    • Location: Southern California
    • Status: offline
    Re: Logic Probe Project C Code Help Needed and Free Give Away 2018/04/04 21:02:45 (permalink)
    +2 (2)
    Using your example of 0.80V, you would represent that as 800mV instead.  2.2V is 2200 mV.  No floating point required.
    #13
    qɥb
    Monolothic Member
    • Total Posts : 3332
    • Reward points : 0
    • Joined: 2017/09/09 05:07:30
    • Location: Jupiter
    • Status: offline
    Re: Logic Probe Project C Code Help Needed and Free Give Away 2018/04/04 21:12:27 (permalink)
    0
    As jtemples just pointed out, you neglected to convert from volts to millivolts.
     

    This forum is mis-configured so it only works correctly if you access it via https protocol.
    The Microchip website links to it using http protocol. Will they ever catch on?
    PicForum "it just works"
    #14
    t1d
    Junior Member
    • Total Posts : 98
    • Reward points : 0
    • Joined: 2015/01/26 15:49:24
    • Location: 0
    • Status: offline
    Re: Logic Probe Project C Code Help Needed and Free Give Away 2018/04/04 21:24:29 (permalink)
    0
    Okay, now I understand. Great idea! I will swap it over. Then, time to breadboard it... Thanks.
    #15
    NorthGuy
    Super Member
    • Total Posts : 5100
    • Reward points : 0
    • Joined: 2014/02/23 14:23:23
    • Location: Northern Canada
    • Status: offline
    Re: Logic Probe Project C Code Help Needed and Free Give Away 2018/04/04 21:42:41 (permalink)
    +1 (1)
    t1dunn
    Well, lets look at an example... A typical TTL logic system uses 0.80v, as the low state threshold, and 2.2v, as the high state threshold. So, all comparisons required floating decimal math... And, that requires float variables. Correct? Maybe I don't understand the use of intergers and floats?



    All you need to do is what ADC reading is at 0.8V and 2.2V. Then you just compare the ADC readings. Your logic probe is on the slow side, so the faster you can do it, the better your logic probe becomes.
     
    DAC and comparator (many PICs have both built-in) would produce much faster logic probe than ADC.
    #16
    t1d
    Junior Member
    • Total Posts : 98
    • Reward points : 0
    • Joined: 2015/01/26 15:49:24
    • Location: 0
    • Status: offline
    Re: Logic Probe Project C Code Help Needed and Free Give Away 2018/04/04 22:17:17 (permalink)
    0
    Hi, NorthGuy,
    Thank you for your suggestions about DAC and comparator. I am using this project as a learning tool, so I won't change horses, mid-stream. But, please give me a rough sketch of what would be needed and I will use it next time.
     
    Presently, I have reviewed my code and see that I need a method to wait for the probe to have voltage on it, in order to initiate setting the CMOS reference voltage. As is, if no voltage is present, the code simply skips that function.
     
    I have looked at getch, but I don't think that is the correct method, as I am not using a keyboard. Ideas?
    #17
    qɥb
    Monolothic Member
    • Total Posts : 3332
    • Reward points : 0
    • Joined: 2017/09/09 05:07:30
    • Location: Jupiter
    • Status: offline
    Re: Logic Probe Project C Code Help Needed and Free Give Away 2018/04/04 22:43:50 (permalink)
    0
    t1dunn
    ...
    Presently, I have reviewed my code and see that I need a method to wait for the probe to have voltage on it, in order to initiate setting the CMOS reference voltage. As is, if no voltage is present, the code simply skips that function.

    Why does the reference voltage setting have to wait for the DUT connection at all?
    Personally, I'd totally decouple the two functions from each other.
    You also have some big problems with your code flow.
    Your "while(1), while(2), while(3) etc. don't make sense, as all non zero values there are treated as "true", so you have a whole heap of loops that never exit.
    Also, you are doing returns from the main() function, which has the effect of resetting your whole device and going back to the start of your code again.
     
    Your code would be much simpler if you just had a single outer loop, say about ten times a second, and checlk the status of your level select pin once each time around the loop.
    LED flashing can be controlled by incrementing variables each time around the loop, then deciding if the LED should be off or on each time.
     

    This forum is mis-configured so it only works correctly if you access it via https protocol.
    The Microchip website links to it using http protocol. Will they ever catch on?
    PicForum "it just works"
    #18
    JorgeF
    Super Member
    • Total Posts : 3299
    • Reward points : 0
    • Joined: 2011/07/09 11:56:58
    • Location: PT/EU @ Third rock from the Sun
    • Status: offline
    Re: Logic Probe Project C Code Help Needed and Free Give Away 2018/04/05 04:31:36 (permalink)
    +1 (1)
    Hi
    t1dunn
    .... I need a method to wait for the probe to have voltage on it, in order to initiate setting the CMOS reference voltage. As is, if no voltage is present, the code simply skips that function.



    Why?
    All logic probes I've worked with have continuos operation.
    When "on the air" they simply react to EMI noise, like other measurement instruments.
     
    Best regards
    Jorge
     
    #19
    t1d
    Junior Member
    • Total Posts : 98
    • Reward points : 0
    • Joined: 2015/01/26 15:49:24
    • Location: 0
    • Status: offline
    Re: Logic Probe Project C Code Help Needed and Free Give Away 2018/04/05 05:52:41 (permalink)
    0
    qɥbWhy does the reference voltage setting have to wait for the DUT connection at all?
    CMOS makes decisions based on the percentage of the tested voltage to the reference voltage. That means that the reference voltage must be measured, to be known. Data sheets aren't always available. And, even when in hand, any difference to the actual DUT voltage would make for reading errors. The math is <1/3 is low and >2/3 is high.
     
    TTL does not work on percentages. It works on set voltages... > 0.80v is low and >2.2v is high. So, no reference voltage testing is needed.
    qɥbPersonally, I'd totally decouple the two functions from each other.
    What is your thinking, on how to accomplish that?
    qɥbYou also have some big problems with your code flow.
    Your "while(1), while(2), while(3) etc. don't make sense, as all non zero values there are treated as "true", so you have a whole heap of loops that never exit.
    Also, you are doing returns from the main() function, which has the effect of resetting your whole device and going back to the start of your code again.
    Excellent! This is the stuff us noobs are too green to see.
    qɥbYour code would be much simpler if you just had a single outer loop, say about ten times a second, and checlk the status of your level select pin once each time around the loop.
    LED flashing can be controlled by incrementing variables each time around the loop, then deciding if the LED should be off or on each time.
    That is something to consider. Thanks for your continued help.
    #20
    Page: 1234 > Showing page 1 of 4
    Jump to:
    © 2018 APG vNext Commercial Version 4.5