New to programming and am having a few issues with some code


Closed Thread
Results 1 to 20 of 20

Hybrid View

  1. #1
    Join Date
    Apr 2012
    Location
    Leicester UK
    Posts
    21


    Did you find this post helpful? Yes | No

    Default Re: New to programming and am having a few issues with some code

    I tried the resistor and the LED separately, with your help and looking through the datasheet again it does seem that it is the configuration settings.

    Demon
    #3: PWMOUT VAR GPIO.0 <-- Is this your POWER LED? You never turn it on, you only define it (or maybe I'm missing something)
    - I was initally going to use these labels instead of the binary code for the pins, but I ended up using the binary numbers as I wanted to be able to turn more than one pin on and off at a time. Though the pin names are left in incase I wish to use them in the future.

    Dave
    I never realised that I needed to set the CMCON0 register as I decided to not look into the comparator section of the datasheet as this is not a function I am using at this time. I'll spend more time reading the rest of the datasheet now to see if there is any other bits I have missed.

    I shall look at the registers later tonight to see if there is anything else I have missed.

    Many thanks for your help.

  2. #2
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default Re: New to programming and am having a few issues with some code

    Dave
    Always wear safety glasses while programming.

  3. #3
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,166


    Did you find this post helpful? Yes | No

    Default Re: New to programming and am having a few issues with some code

    Actually Robert, He is comanding the power led to light every time he is sending the commands to the other led's with any of the GPIO statements like: GPIO = %00010001
    Dave Purola,
    N8NTA
    EN82fn

  4. #4
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,172


    Did you find this post helpful? Yes | No

    Default Re: New to programming and am having a few issues with some code

    Ah, thanks Dave, now I see it as plain as the nose on my face.

  5. #5
    Join Date
    Apr 2012
    Location
    Leicester UK
    Posts
    21


    Did you find this post helpful? Yes | No

    Default Re: New to programming and am having a few issues with some code

    Mackrackit - thanks for the link its very useful reading.


    DEFINE OSC 8

    'GP2 (AN2) IS FOR TARGET POSITION (INPUT)
    'GP4 DIRECTION SIGNAL CW (OUTPUT)
    'GP5 DIRECTION SIGNAL CCW (OUTPUT)
    'GP0 POWER (OUTPUT)
    'GP1 (AN1) CURRENT POSITION (INPUT)

    'REGISTERS
    OPTION_REG = %11000000
    INTCON = %11000000
    PIE1 = %01000000
    PIR1 = %00000000
    OSCCON = %01110001
    TRISIO = %00001110
    ANSEL = %01010110
    CCP1CON = %00000000
    CMCON0 = %00000111

    INCLUDE "DT_INTS-14.bas" ' Base Interrupt System
    INCLUDE "ReEnterPBP.bas" ' Include if using PBP interrupts

    ;---------------------------------------------------------------------------
    wsave VAR BYTE $20 SYSTEM ' location for W if in bank0
    ;wsave VAR BYTE $70 SYSTEM ' alternate save location for W
    ' if using $70, comment wsave1-3

    ' --- IF any of these three lines cause an error ?? ------------------------
    ' Comment them out to fix the problem ----
    ' -- Which variables are needed, depends on the Chip you are using --
    wsave1 VAR BYTE $A0 SYSTEM ' location for W if in bank1
    'wsave2 VAR BYTE $120 SYSTEM ' location for W if in bank2
    'wsave3 VAR BYTE $1A0 SYSTEM ' location for W if in bank3
    ' --------------------------------------------------------------------------

    'OUTPUT PINS
    DIRCW VAR GPIO.4
    DIRCCW VAR GPIO.5
    PWMOUT VAR GPIO.0

    'VARIABLES
    TARGET VAR WORD bank0
    TARGET_L VAR Target.BYTE0
    TARGET_H VAR TARGET.byte1
    CURRENT VAR WORD bank0
    CURRENT_L VAR current.byte0
    CURRENT_H VAR current.byte1

    ASM
    INT_LIST macro ; IntSource, Label, Type, ResetFlag?
    INT_Handler AD_INT, _CurrentPos, PBP, yes
    endm
    INT_CREATE ; Creates the interrupt processor
    ENDASM

    'READ TARGET POSITION FROM POT
    ADCON0 = %00001011 'TARGET POSITION READ
    REPEAT
    PAUSE 100
    UNTIL ADCON0.1 = 0

    TARGET.lowbyte = ADRESL
    Target.HighByte = ADRESH

    ADCON0 = %00000111 'CURRENT POSITION ADC SETUP

    'MAIN PROG
    MAIN:
    IF CURRENT=TARGET THEN
    gosub motorbreak
    else
    if current > target then
    gosub motorcw
    else
    gosub motorccw
    endif
    endif
    GOTO MAIN

    'SUB PROGRAM
    MotorBreak:
    GPIO = %00110001
    return

    MotorCW:
    GPIO = %00010001
    Return

    MotorCCW:
    GPIO = %00100001
    Return

    CurrentPos:
    current.lowbyte = ADRESL
    Current.HighByte = ADRESH
    @ INT_RETURN ;RETURN

    END
    I appear to be getting close now.

    The LEDs now light as expected. Which is good news. I temporary added a piece of code to turn the Power LED off everytime main section of code cycled through to prove that the PIC wasn't hanging.

    The power LED was flashing as expected.

    My only question is with the interupts, when the main program keeps running through the main loop it doesn't appear to update the current position when the current postion potentiometer is changed. With DT Interupts do I have to reset the ADCON0 GO/DONE bit or does the DT interupts automatically.

    Thank you for your time.

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


    Did you find this post helpful? Yes | No

    Default Re: New to programming and am having a few issues with some code

    Steve

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

  7. #7
    Join Date
    Apr 2012
    Location
    Leicester UK
    Posts
    21


    Did you find this post helpful? Yes | No

    Default Re: New to programming and am having a few issues with some code

    My apologies, I thought that previous comment was about the initial target potentiometer and not the current (feedback) potentiometer

    So I'll have to reset the go/done bit. Thank you very much

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