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
Bookmarks