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

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

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

    Success.

    Thank you to everyone for all your help.

    I've posted the working code as an example for anyone who wants to use it as an example.

    clear

    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

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

    'Variables
    Target var word
    Current VAR WORD

    ADCON0 = %00001011 'TARGET POSITION READ
    pause 100

    TARGET.lowbyte = ADRESL
    Target.HighByte = ADRESH

    'MAIN PROG
    MAIN:
    pause 100
    GPIO = %00000000
    pause 100
    IF CURRENT = TARGET THEN
    gosub motorbreak
    else
    if current > target then
    gosub motorcw
    else
    gosub motorccw
    endif
    endif

    ADCON0 = %00000111 'CURRENT POSITION ADC SETUP

    GOTO MAIN

    'SUB PROGRAM
    MotorBreak:
    GPIO = %00110001
    return

    MotorCW:
    GPIO = %00010001
    Return

    MotorCCW:
    GPIO = %00100001
    Return

    CurrentPos:
    pause 10
    GPIO.0 = 0
    current.lowbyte = ADRESL
    Current.HighByte = ADRESH
    'ENDIF
    @ INT_RETURN ;RETURN

    END
    Right onto its next stage of its evolution.

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