I don't understand this code!


Closed Thread
Results 1 to 40 of 47

Hybrid View

  1. #1
    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.

  2. #2
    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 !

  3. #3
    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...

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


    Did you find this post helpful? Yes | No

    Default

    The waveform posted by Picuser is what I want the output to look like. The actual output is the inverse and I don't understand it. Perhaps my compiler is corrupted?

  5. #5
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Russ Kincaid View Post
    The waveform posted by Picuser is what I want the output to look like. The actual output is the inverse and I don't understand it. Perhaps my compiler is corrupted?
    I'd highly doubt your compiler is corrupted, but maybe a reinstall is in order.
    And I think post #16 might be your problem in the first place.

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


    Did you find this post helpful? Yes | No

    Default

    Thanks for your reply. PIC_USER is correct in post #16, both GPIO.0 and GPIO.1 are at the same level in time periods 2 and 4, but they are both low. I want them to be high. Can someone tell me what is wrong with my code?

    BTW, I changed to TRISIO=0, didn't make a difference.

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


    Did you find this post helpful? Yes | No

    Smile your second (inverse) code

    Hi Russ,
    I think with your original pins (GPIO.0 and GPIO.1), and your second (inverse) code:

    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

    ...and your diodes reversed and the resistor tied to ground (as skimask said).

    Your two LEDs will not be on at the same time... (try it)

    I still would like to know between which points are you measuring the wave (voltage) from?

    -Adam-
    Ohm it's not just a good idea... it's the LAW !

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


    Did you find this post helpful? Yes | No

    Default

    Hi Pic_User. Yes, I know that, but why cannot I connect the LEDs to + and pulse to ground? I changed the program, trying to zero in on the probem. Now GPIO.1 pulses to ground like I want but GPIO.0 pulses positive in phase with GPIO.1. I would not expect GPIO.0 to change at all.

    high GPIO.0 'INITIAL CONDITIONS
    high GPIO.1

    START:
    low GPIO.1
    high GPIO.0
    PAUSEUS 4168 ' ON TIME
    high GPIO.1
    PAUSEUS 4167 'DEAD TIME, BOTH high
    high GPIO.1
    PAUSEus 4168 'FOR 4.168 MILLISECONDS
    high GPIO.1
    PAUSEUS 4167 'DEAD TIME

    GOTO START '60 HZ FREQUENCY

    END

    I will post the final circuit so you can see what I am trying to do. I want to replace the 555, flip flops and gate with the PIC.
    Attached Images Attached Images  
    Last edited by Russ Kincaid; - 7th May 2007 at 17:10.

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