So I should bridge pin 17 and PORTB.0 with a 10k resistor? or do I run it to ground? or what?
So I should bridge pin 17 and PORTB.0 with a 10k resistor? or do I run it to ground? or what?
You might also want to consider a series resistor between your PWM output pin & RB0/INT0 *just in case*.
If you're new to all this, the series resistor can keep you from blowing an I/O-pin while tinkering. If you
accidentally make both pins an output, this resistor can save your bacon.
Code:pull-down 1K RB0----------|-/\/\/\/\--PWM pin | 10K pull-down |--/\/\/\/\----GND or pull-up 1K RB0----------|-/\/\/\/\--PWM pin | 10K pull-up |--/\/\/\/\----+5V
OK, I got a chance to test it today and neither the HWPM nor the +5V trigger to PORTA.2 work. I implemented those changes you suggested and still it doesn't work. Any ideas?
can you post your current code?
Steve
It's not a bug, it's a random feature.
There's no problem, only learning opportunities.
' Connect analog input to (RA0)
' Connect clocks to PORTB
' PORTB.0 is the Reset Clock
' PORTB.1 is the Vphase1 clock
' PORTB.2 is the Vphase2 clock
' PORTB.3 is the Hphase1 clock
' PORTB.4 is the Hphase2 clock
' The reset will be connected to a HWPM clock pin #17, USE FEEDBACK WIRE!!
' Connect pin 2 from the DB9 connector to PORTC.6
' Have a +5V source ready to touch PORTA.2 to trigger clocking process
include "modedefs.bas"
' Define ADCIN parameters
Define ADC_BITS 8 ' Set number of bits in result
DEFINE OSC 20 ' Sets clock speed to 20Mhz
Define ADC_CLOCK 4 ' Set clock source (3=rc)
Define ADC_SAMPLEUS 50 ' Set sampling time in uS
HPWM 1,64,3600 ' Supposed to send HPWM 3.6KHZ at 25% duty
INTCON2 = %0100000 ' External Interrupt on Rising Edge
INTCON.7 = 0 ' Disables global interrupts
TRISA = %11111111 ' Set PORTA to all input
ADCON1 = %00001101 ' Set PORTA analog, except for pin 2
TRISB = %00000001 ' Set PORTB to all output, except for bit 0
Pause 500 ' Wait .5 second
Pause 500 ' Wait .5 second
horizpulse var byte
vertpulse var byte
adval var byte ' Create adval to store result
horizpulse = 1 ' Initialize counters, initial states
vertpulse = 1
PORTB.1 = 0
PORTB.2 = 0
PORTB.3 = 1
PORTB.4 = 0
buttonloop:
IF PORTA.2 = 1 then
GOTO vertloop
else
GOTO buttonloop ' Waits for 5V that signals shutter is closed
ENDIF
vertloop:
horizpulse = 1
PORTB.1 = 1
PAUSEUS 139
PORTB.1 = 0
PORTB.2 = 1
PAUSEUS 139
PORTB.1 = 1
PORTB.2 = 0
PAUSEUS 139
PORTB.1 = 0
PAUSEUS 270
vertpulse = vertpulse + 1
IF vertpulse < 512 THEN
GOTO horizloop
ELSE
GOTO buttonloop
ENDIF
horizloop:
INTCON.1 = 0 ' Resets interrupt flag to 0
Resetcheck: ' Loops back to make sure
' the PORTB.3 goes low and
IF INTCON.1 = 0 THEN ' PORTB.4 goes high as close
GOTO Resetcheck ' to the external trigger's
ELSE ' rising edge as possible
ENDIF
PORTB.3 = 0
PORTB.4 = 1
PAUSEUS 139
PORTB.4 = 0
PORTB.3 = 1
PAUSEUS 15
ADCIN 0, adval ' A/D 8 bit value from PORTA.0 into adval
SEROUT2 PORTC.6,16416,[BIN8 adval,13,10] ' Output 8 bit word serially to PC from C.6
PAUSEUS 87
horizpulse = horizpulse + 1
IF horizpulse < 784 THEN
GOTO horizloop
ELSE
PAUSEUS 270
GOTO vertloop
ENDIF
END
about this section
seems to be a common used here to exit from a IF THEN statement... sorry that's a bad practice IMHO and can overflow the stack really fast.Code:vertpulse = vertpulse + 1 IF vertpulse < 512 THEN GOTO horizloop ELSE GOTO buttonloop ENDIF horizloop:
about thisCode:vertpulse = vertpulse + 1 IF vertpulse >= 512 THEN buttonloop horizloop:
copy/paste error !?! something missing between ELSE and ENDIF ?!?Code:IF INTCON.1 = 0 THEN ' PORTB.4 goes high as close GOTO Resetcheck ' to the external trigger's ELSE ' rising edge as possible ENDIF
For HPWM... looks that you'll have to do it manually... the following is an example for a PIC18F2320
Code:' PIC18F2320 TRISC.2=0 ' CCP1 AS OUTPUT Tmr2dutyvar VAR WORD Tmr2dutyvar=86 ' ((1/3600)/4)/20Mhz / 16(prescaller) PR2=$57 ' load frequency period (PWM freq=3.6 KHZ) 'set Duty cycle CCP1CON.5=Tmr2dutyvar.1 CCP1CON.4=Tmr2dutyvar.0 CCPR1L =(tmr2dutyvar>>2) T2CON=%00000110 ' start timer 2 ' set prescaler = 16 CCP1CON = %00001100 ' pwm mode for CCP1 HERE: GOTO HERE
Steve
It's not a bug, it's a random feature.
There's no problem, only learning opportunities.
Bookmarks