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

    Default I don't understand this code!

    I am trying to generate a quasi sine wave at 60 hz. The program runs but the waveform is upside down. I could change the circuit to accept the upside down wave, but I would like to know what is going on. This is my simple code:
    REM DEVICE = 12F675 '12F629 CAN ALSO BE USED
    REM USE INTERNAL OSCILLATOR, OUTPUT IS ON GP4 (PIN 3)
    REM CONFIGURATION: INTOSC CLOCKOUT, WDT DISABLED, PWR UP ENABLED,
    'MCLR = OUTPUT PIN, BROWN OUT DISABLED, NO PROTECTION
    REM 60 HZ OUTPUT IS ON PINS 7 AND 6
    REM OSCILLATOR CHOICE: USE 101, INTOSC, CLKOUT
    OPTION_REG.5 = 0 'OTHERWISE GPIO.2 IS AN INPUT
    TRISIO = %111111 'SETS ALL PORTS TO OUTPUT
    ANSEL = 0 'SETS ALL DIGITAL MODE
    DEFINE OSCCAL_1K 1 'FOR OSCILLATOR CALIBRATION, DON'T KNOW HOW IT WORKS

    HIGH GPIO.0 'INITIAL CONDITIONS
    HIGH GPIO.1

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

    GOTO START '60 HZ FREQUENCY

    END

    If I change all highs to lows and all lows to high in the loop, I get the idenical same hex code. I would expect that
    high gpio.0
    highgpio.1
    start:
    low gpio.1
    would give a different hex code than
    high gpio.0
    high gpio.1
    start:
    high gpio.1

    Russ

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


    Did you find this post helpful? Yes | No

    Question 60 Hertz quasi sine wave

    Hi Russ,

    Could you explain how the waveform is upside down?
    Do you mean that the 60 Hertz quasi sine wave is upside down on your oscilloscope display? Switch your scope “triggering” from plus(+) to minus(-).

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

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


    Did you find this post helpful? Yes | No

    Default

    Thanks, I should have said that: I want the output to be low for the short time (4+ms) and high for the long time (12+ms). I think the program should do that, but it doesn't. The output is high for the short time and low for the long time.

  4. #4
    Join Date
    Jul 2003
    Location
    USA - Arizona
    Posts
    156


    Did you find this post helpful? Yes | No

    Default

    Your main code looks fine:
    Code:
    START:
    LOW GPIO.1 
    PAUSEUS 4168 ' ON TIME
    HIGH GPIO.1
    PAUSEUS 4167 'DEAD TIME 
    LOW GPIO.0 'SETS PIN 7 LOW
    PAUSEus 4168 'FOR 4.168 MILLISECONDS 
    HIGH GPIO.0
    PAUSEUS 4167 'DEAD TIME
    Your startup code does not:
    Code:
    TRISIO = %111111
    This sets all pins to <U>inputs</U>. You want to use:
    Code:
    TRISIO = %001000 '(since GPIO3 is input only anyway)

  5. #5
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by languer View Post
    Code:
    TRISIO = %001000 '(since GPIO3 is input only anyway)
    Except for the fact that HIGH and LOW automatically set the pins as outputs...

    Now then...what is this output thing? Is this a 2 bit R/2R D/A ladder type setup or what is it?

  6. #6
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    If it was me, i would use a timer interrupt, but add somes extra filter outside.

    I don't understand what you mean by
    Quote Originally Posted by Russ Kincaid
    The program runs but the waveform is upside down. I could change the circuit to accept the upside down wave,
    Last edited by mister_e; - 6th May 2007 at 09:52.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

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