I don't understand this code!


Closed Thread
Results 1 to 40 of 47

Hybrid View

  1. #1
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    I'm thinking it might be time to post your schematic so we can quit guessing and start fixin' !

  2. #2
    Join Date
    Jan 2006
    Location
    New Hampshire, USA
    Posts
    107


    Did you find this post helpful? Yes | No

    Default

    This is a very simple circuit, and not part of the problem, I believe.

    Russ
    Attached Images Attached Images  

  3. #3
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Russ Kincaid View Post
    This is a very simple circuit, and not part of the problem, I believe.

    Russ
    Turn the LEDs around and connect them to ground.
    When you apply a logic 0 to the pin, the pin sinks current and the LED lights...when you apply a logic 1 to the pin, the LED has the same voltage on both sides and doesn't light up...negative logic.
    That's why everything is backwards...but it's really not...it's working just as designed.

  4. #4
    Join Date
    Jan 2006
    Location
    New Hampshire, USA
    Posts
    107


    Did you find this post helpful? Yes | No

    Default

    No, No, not working as designed. I know I can turn the LEDs around, but I want to know why I have to do that. I suppose I could write the program to do the opposite of what I want and see what happens.

  5. #5
    Join Date
    Apr 2006
    Location
    New Hampshire USA
    Posts
    298


    Did you find this post helpful? Yes | No

    Thumbs up I vote to re-order the code.

    Hi Russ,

    The waveform and any talk about HIGH / LOW is assumed to be in reference to the (ground / common / Vss) of the PIC. Your LEDs are referenced to the plus “rail” of the supply. That would make the LED output appear to be (upside down / negative logic). You could rewire the LEDs or re-order the code.

    By the way, it is very interesting to put both LEDs on the single 1k resistor. Causing the voltage to vary differently when one, two or none of the LEDs are on! Getting, the same reading on a true RMS and a cheap 0.7 of peak meter is not an easy task! Where do you measure the voltage?

    I vote to re-order the code.
    -Adam-
    Ohm it's not just a good idea... it's the LAW !

  6. #6
    Join Date
    Jan 2006
    Location
    New Hampshire, USA
    Posts
    107


    Did you find this post helpful? Yes | No

    Default

    I re-wrote the program to produce the opposite waveform, but it is the same waveform:
    LOW GPIO.0 'INITIAL CONDITIONS
    LOW GPIO.1

    START:
    HIGH GPIO.1
    PAUSEUS 4168 ' HIGH TIME
    LOW GPIO.1
    PAUSEUS 4167 'DEAD TIME, BOTH LOW
    HIGH GPIO.0 'SETS PIN 7 HIGH
    PAUSEus 4168 'FOR 4.168 MILLISECONDS
    LOW GPIO.0
    PAUSEUS 4167 'DEAD TIME

    GOTO START '60 HZ FREQUENCY

    END

    Since both programs produce the same waveform, I guess my only option is to turn the LEDs around!
    My circuit is only for testing. If I were driving solid state relays they would burn up when both were on.

  7. #7
    Join Date
    Apr 2006
    Location
    New Hampshire USA
    Posts
    298


    Did you find this post helpful? Yes | No

    Post oh-oh

    Russ, the code will cause both LEDs to be on at the same time, even if the LEDs are referenced to ground.
    GPIO.0 and GPIO.1 are the same level in the “second” and the “forth” time increment.
    The previously attached waveform drawing shows this.
    http://www.picbasic.co.uk/forum/atta...1&d=1178466510
    You may have forgotten 4.168 milliseconds is one quarter (“one quadrant”) of a full cycle (16.667) – not one half.
    -Adam-
    Ohm it's not just a good idea... it's the LAW !

  8. #8
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Might sound a bit silly, but, maybe if you drew us a quick picture of what you want the output to be, like if it was a picture from an o'scope, we might be able to better understand what you actually want.
    The last post by Pic_User sounds like that might be the problem, simple mistake, easily fixed...

Similar Threads

  1. Reading in Manchester code
    By brid0030 in forum Code Examples
    Replies: 0
    Last Post: - 10th March 2009, 21:55
  2. How much code space do PBP statements use.
    By Darrel Taylor in forum Code Examples
    Replies: 5
    Last Post: - 13th February 2009, 21:31
  3. Loop with two motor and 2 sensors
    By MrRoboto in forum mel PIC BASIC
    Replies: 4
    Last Post: - 8th December 2008, 23:40
  4. Making Program Code Space your playground...
    By Melanie in forum Code Examples
    Replies: 15
    Last Post: - 19th July 2008, 08:26
  5. Re-Writing IF-THEN-AND-ENDIF code?
    By jessey in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 18th August 2006, 17:23

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