what is wrong in this code


Closed Thread
Results 1 to 14 of 14

Hybrid View

  1. #1
    Join Date
    Jan 2012
    Posts
    24


    Did you find this post helpful? Yes | No

    Default Re: what is wrong in this code

    Quote Originally Posted by HenrikOlsson View Post
    When C1Out is 1 you set PortB.0 HIGH and when C1Out is 0 you set PortB.1 HIGH. But there is no code in the loop to set either of the outputs LOW again.
    Code:
    lop:
      if C1Out = 1 THEN
        PortB.0 = 1   ' One on
        PortB.1 = 0   ' The other off
      ELSE
        PortB.0 = 0   ' On off
        PortB.1 = 1   ' The other on
      ENDIF
    GOTO lop
    yah HenrikOlsson help me on that edit where necessary so that it can work as i want, iam a begginer in the pics progrmming, thanx indvance

  2. #2
    Join Date
    Jan 2012
    Posts
    24


    Did you find this post helpful? Yes | No

    Default Re: what is wrong in this code

    Quote Originally Posted by chitalula View Post
    yah HenrikOlsson help me on that edit where necessary so that it can work as i want, iam a begginer in the pics progrmming, thanx indvance
    sayzer i tried to run your but it didn't do anything, i don't know why. and i need a comparison in my code can you add too?

  3. #3
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,610


    Did you find this post helpful? Yes | No

    Default Re: what is wrong in this code

    yah HenrikOlsson help me on that edit where necessary so that it can work as i want, iam a begginer in the pics progrmming, thanx indvance
    I already DID just that. The code in my previous message IS edited so it should work the way I think you want.

  4. #4
    Join Date
    Jan 2012
    Posts
    24


    Did you find this post helpful? Yes | No

    Default Re: what is wrong in this code

    Quote Originally Posted by HenrikOlsson View Post
    I already DID just that. The code in my previous message IS edited so it should work the way I think you want.
    i tried to do as you told me but it didn't work as i want, led at portb.1 is always on even if the voltages at RA0 pin is changed. it seems the comparison is not working on the if statement, still have a problem.
    thanx in advance

  5. #5
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default Re: what is wrong in this code

    The code and the circuit in my post works with no problem in simulation.
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  6. #6
    Join Date
    Jan 2012
    Posts
    24


    Did you find this post helpful? Yes | No

    Default Re: what is wrong in this code

    Quote Originally Posted by chitalula View Post
    yah HenrikOlsson help me on that edit where necessary so that it can work as i want, iam a begginer in the pics progrmming, thanx indvance
    thanx for your suggestion. on stimulation if the input voltage equal to vref else statement always and if the input voltage is higher than or less than Vref else statement is executed too. it seems the "if statement" is not functioning, have you any solution on that case, i have no way to go forward , help me please

  7. #7
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,610


    Did you find this post helpful? Yes | No

    Default Re: what is wrong in this code

    I'm pretty sure that the IF statement executes as it should. The problem is likely that the C1Out doesn't actually toggle.

    According to your schematic in the first post you have one input to RA0 and the other to RA2. As far as I can see in the datasheet, section 12.1, the inputs to comparator 1 is RA0 and RA3.

    /Henrik.

  8. #8
    Join Date
    Jan 2012
    Posts
    24


    Did you find this post helpful? Yes | No

    Default Re: what is wrong in this code

    Thanx alot henrikolsson and sayzer for all of your suggestions, the problem was in configuration of cmcon, now it work as i want, thanx in advance

  9. #9
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,610


    Did you find this post helpful? Yes | No

    Default Re: what is wrong in this code

    How can it work when the two inputs, according to your schematic, are wired to two different comparators? What did you change CMCON to to make it work?

  10. #10
    Join Date
    Jan 2012
    Posts
    24


    Did you find this post helpful? Yes | No

    Default Re: what is wrong in this code

    Quote Originally Posted by HenrikOlsson View Post
    How can it work when the two inputs, according to your schematic, are wired to two different comparators? What did you change CMCON to to make it work?
    HenrikOsson my big problem was in CMCON register configuration, i leave my previous circuit and i took the circuit uploaded by sayzer. and i edit some code there by puting my own code

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