A Defines Request


Closed Thread
Results 1 to 23 of 23

Hybrid View

  1. #1


    Did you find this post helpful? Yes | No

    Default Re: A Defines Request

    Tris Registers?

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


    Did you find this post helpful? Yes | No

    Default Re: A Defines Request

    Quote Originally Posted by mark_s View Post
    Tris Registers?
    The OP needs to learn about those also, but if I am not missing something his code is using commands that set TRIS in the background.
    Dave
    Always wear safety glasses while programming.

  3. #3


    Did you find this post helpful? Yes | No

    Default Re: A Defines Request

    Quote Originally Posted by mackrackit View Post
    The OP needs to learn about those also, but if I am not missing something his code is using commands that set TRIS in the background.
    Dave,

    Did not realize that. thanks.

    But, I always set them even if it's not needed.

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


    Did you find this post helpful? Yes | No

    Default Re: A Defines Request

    Quote Originally Posted by mark_s View Post
    But, I always set them even if it's not needed.
    That is good practice along with good code comments. It does not hurt a thing.
    Dave
    Always wear safety glasses while programming.

  5. #5
    Join Date
    May 2007
    Posts
    604


    Did you find this post helpful? Yes | No

    Default Re: A Defines Request

    You can follow the same topic here How do I learn configuration?
    Why pay for overpriced toys when you can have
    professional grade tools for FREE!!!

  6. #6
    Join Date
    Feb 2011
    Posts
    19


    Did you find this post helpful? Yes | No

    Default Re: A Defines Request

    Dear Dave,

    Attached is the latest program. I did add the suggested capacitor between the +-5 supply lines. Somehow I smoked a regulator and PIC trying it. I got new chips and retried our program to flicker the LEDs and that worked fine. I tried the attached program (with your suggested OSC 48 configs ADCON1 and CMCON plus the OSCCON from the LED program) . It sounded like it was driving the valve coil but the 5VDC regulator started to smoke then it settled down and looked ok with one LED lit except the program, the same as the one which works on the stamp, didn't change anything when the POT was turned. Eventually I reloaded the program to make sure I hadn't fried the PIC chip and tried it with a new regulator. This time all three LEDs were on bright and the regulator shot a bit of plastic (about half the front) and hit me in the stomach. Any suggestions?

    With assistance from the other forum I located the Bits section and saw the config table. I wonder why the stuff they specify such as config1L PLLDIV has extra syntax like _CONFIG1L, _PLLDIV_1_1L and similar for all specified bits. Where is that documented?

    Also, your ADCON1 'Set all I/O's to Digital and CMCON 'Disable Comparators would seem to turn off the analog function needed on pin 2 aka. PORTA.0 which is supposed to read a Pot and Capacitor for the RCTIME command. Could that have anything to do with blowing up the regulator? I'll try it without after posting this.

    Thanks,
    Kirk
    Attached Files Attached Files

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


    Did you find this post helpful? Yes | No

    Default Re: A Defines Request

    I can not look at your current code where I am at. If it were posted inline with code tags I could.

    ADCON1 = 15
    Turns off the hardware ADC
    CMCON = 7
    Turns off the hardware comparators.

    RCTIME is a software command having nothing to do with the above.

    Running the LEDs without a resistor could be overloading the regulator, at least until they pop. Is the schematic posted really what you are working with? Even with a Stamp resistors are needed.
    Dave
    Always wear safety glasses while programming.

  8. #8
    Join Date
    Feb 2011
    Posts
    19


    Did you find this post helpful? Yes | No

    Default Re: A Defines Request

    Dave,

    Retesting confirms, your latest suggestion burned out my regulator and a PIC18F4550 in addition to smacking me in the stomach. (Now I see why your "Wear Safety Glasses" comment is serious.)
    ADCON1 = 15 ' Set all I/Os to Digital
    CMCON = 7 ' Disable Comparators
    Commenting out those two statements got me back to the original post on this thread. Now it simply doesn't work even though the current regulator works shown via voltmenter and PIC works proven by reloading the program.

    LED resisters are NOT needed on the Stamp. They were not needed when running the PIC with the LED test either, except to protect the LED's on start up - they worked fine when added after powered up. What LED resistor would you recommend?

    The schematic is exactly the same except for the crystal and its caps which aren't needed on the Stamp and the fact I forgot to show a cap across the regulator ground and 5V out, which can be seen in the photo. In fact the photo would be exactly the same when using the Stamp except wires connect the Stamp board with the IRL530's and the POT circuit and the absence of the PIC chip.

    So back to the original question for this thread. What do I need to change to make it work? Thanks.

    Kirk

    PS: I don't know what you mean by code tags but here's my current code.
    Code:
    'Hydraulic S-Curve Swing Test reducing limit shock
    '   Chips: PIC 18F4550 2x IRL530
    '   Inputs: 10K pot for actuator position
    '            ~USB for position control request
    '   Outputs: PWM for Proportional Servo-Valve
    '            ~USB for position report 
    '---------------
    INCLUDE "bs2defs.bas"
    DEFINE OSC 48
    @ __CONFIG   _CONFIG1L, _PLLDIV_1_1L & _CPUDIV_OSC1_PLL2_1L & _USBDIV_2_1L
    @ __CONFIG   _CONFIG1H, _FOSC_HSPLL_HS_1H
    @ __CONFIG   _CONFIG2H, _WDT_OFF_2H & _WDTPS_512_2H
    @ __CONFIG   _CONFIG2L, _PWRT_ON_2L & _VREGEN_ON_2L
    @ __CONFIG   _CONFIG3H, _PBADEN_OFF_3H & _MCLRE_OFF_3H
    @ __CONFIG   _CONFIG4L, _LVP_OFF_4L & _XINST_OFF_4L
    'ADCON1 = 15               ' Set all I/Os to Digital
    'CMCON = 7                 ' Disable Comparators
    OSCCON = %01110000
    
    'INPUT
    ArmPosIn      VAR PORTA.0     'Pot for swing arm position
    
    'OUTPUTS for PWM
    PWA              VAR PORTC.0
    PWB             VAR PORTC.1
    
    'DISPLAY LED's
    LGl           VAR PORTA.2 
    LRl          VAR PORTA.3 
    LYl           VAR PORTA.4 
    LGr          VAR PORTB.4 
    LRr           VAR PORTB.3 
    LYr           VAR PORTB.2 
     
    'CONSTANTS
    UpState     CON 0
    DnState     CON 1
    
    'VARIABLES
    ArmPos          VAR WORD
    CurrentState      VAR Bit
    Charge            VAR Word
    ChgLim          VAR Word 
    DnLimit     VAR Word
    DnTrans     VAR Word     
    UpTrans     VAR Word    
    UpLimit     VAR Word 
         
    'Initialize
    Charge = 0
    DnLimit = 100
    DnTrans = 200
    UpTrans = 800
    UpLimit = 900
    
    'Main Loop
    Begin:
    While 0 = 0
    LOW LGl
    LOW LRl
    LOW LYl
    LOW LGr
    LOW LRr
    LOW LYr
    
      HIGH ArmPosIn                ' charge the cap
      PAUSE 1                      '   for 1 ms
      RCTIME ArmPosIn, 1, ArmPos   ' measure RC discharge time
    
    ChgLim = 1<<8 - 1
    
    IF ArmPos >= UpLimit THEN
        CurrentState = DnState
        ChgLim = 0
        ENDIF
    IF ArmPos <= DnLimit THEN
        CurrentState = UpState
        ChgLim = 0
        ENDIF
    
     IF CurrentState = UpState AND ArmPos < DnTrans THEN
        GOSUB AccelUp
        GOTO Begin
     ENDIF
     IF CurrentState = UpState AND ArmPos < UpTrans THEN
        GOSUB FastUp
        GOTO Begin
     ENDIF
     IF CurrentState = UpState AND ArmPos < UpLimit THEN
        GOSUB DecelUp
        GOTO Begin
     ENDIF
     IF CurrentState = DnState AND ArmPos > UpTrans THEN
        GOSUB AccelDn
        GOTO Begin
     ENDIF
     IF CurrentState = DnState AND ArmPos > DnTrans THEN
        GOSUB FastDn
        GOTO Begin
     ENDIF
     IF CurrentState = DnState AND ArmPos > DnLimit THEN
        GOSUB DecelDn
     ENDIF
    Wend
    
    AccelUp:        '100 - 200 -> 0 - ChgLim
    Charge = (ArmPos - 100) * (ChgLim / 100)
    HIGH LGl
    GOSUB Coil_Output
    RETURN
    
    AccelDn:        '900 - 800 -> 0 - ChgLim
    Charge = ABS (900 - ArmPos) * (ChgLim / 100)
    HIGH LGr
    GOSUB Coil_Output
    RETURN
    
    FastUp:          'max speed
    Charge = ChgLim
    HIGH LRl
    GOSUB Coil_Output
    RETURN
    
    FastDn:          'max speed
    Charge = ChgLim
    HIGH LRr
    GOSUB Coil_Output
    RETURN
    
    DecelUp:        '800 - 900 -> ChgLim - 0
    Charge = (ArmPos - 800) * (ChgLim / 100)
    HIGH LYl
    GOSUB Coil_Output
    RETURN
    
    DecelDn:        '200 - 100 -> ChgLim - 0
    Charge = ABS (100 - ArmPos) * (ChgLim / 100)
    HIGH LYr
    GOSUB Coil_Output
    RETURN
    
    Coil_Output:
    ' PWM output code - 8 bit 
    Charge = ABS Charge MAX ChgLim 'Stop negatives when tweaking limits
    IF CurrentState = UpState THEN
    'Up: Coil A = Charge, B = 0
       PWM PWA,Charge,250
       LOW PWB
    ELSE
    'Dn: Coil A = 0, B = Charge
       LOW PWA
       PWM PWB,Charge,250
    ENDIF
    RETURN
    END
    Last edited by Archangel; - 20th March 2011 at 07:19. Reason: ADD Code Tags

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