-
Also, what if I just send the character representation of the 8-bit sample? Then Matlab could convert that into a decimal on the PC. Then every byte of true data would be sent as 1 byte, not 8 bytes. I am going to mess around with different configurations of the serout2 command to see if there is any change in the execution times.
In addition, what is the general convention for estimating the frequency on the HPWM clock? like if i wanted it to go slower, would i use a smaller number?
-
OK, did some more testing today. Here are the results:
with the ADCIN 0 line and the SEROUT2 PORTC.6,16390,[adval] line, the high time was 410usec, which i suppose is better than 540usec from before. So I wrote the HPWM as follows:
HPWM 1,31,1221
now the reset and the horizontals work fine, but it appears that whenever the HPWM is running, the verticals don't. Can anyone explain this to me? thanks.
-
I also tried the HSEROUT commands and I could get the command to execute faster, however, I think I am trying to receive from the wrong port. I have C.6 wired to the PC and nothing is coming in. In fact, Hyperterminal says it can't even open the port. Also, I looked at the Logic Analyzer output with this new command structure (i mean HSEROUT instead of SEROUT2) and it appears that the H1 and H2 are exactly in phase, instead of the 180 degrees out of phase which they should be. Below is my updated code, notice the commands that show B.3 and B.4 are opposite:
' 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 HSEROUT parameters
DEFINE HSER_TXSTA 24h ' High speed baud generator
DEFINE HSER_BAUD 57600 ' 57600 baud rate
' Define HPWM parameters
DEFINE HPWM1_TIMER 2
DEFINE CCP1_REG PORTC
DEFINE CCP1_BIT 2 ' RC2
TRISC.1 = 0 ' HPWM automatically does this for you, but just in case
CCP1CON = %00001100 ' PWM mode
HPWM 1,31,3600 ' RC2/CCP1 3.6kHz @ ~1/8% duty
' Define interrupt parameters
INTCON2 = %01000000 ' External Interrupt on Rising Edge
INTCON.7 = 0 ' Disables global interrupts
TRISA = %11111111 ' Set PORTA to all input
ADCON1 = %00001110 ' Set PORTA digital, except for bit 0
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
PORTB.5 = 0 ' LED off indicates that the camera is not transferring data
buttonloop:
IF PORTA.2 = 1 then
PORTB.5 = 1
GOTO vertloop
else
PORTB.5 = 0
GOTO buttonloop ' Waits for 5V that signals shutter is closed
ENDIF
vertloop:
horizpulse = 1
PORTB.1 = 1
PAUSEUS 280
PORTB.1 = 0
PORTB.2 = 1
PAUSEUS 280
PORTB.1 = 1
PORTB.2 = 0
PAUSEUS 280
PORTB.1 = 0
PAUSEUS 820
vertpulse = vertpulse + 1
IF vertpulse < 512 THEN
GOTO horizloop
ELSE
PORTB.5 = 0
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 rising edge as possible
ENDIF
PORTB.3 = 0
PORTB.4 = 1
PAUSEUS 140
PORTB.4 = 0
PORTB.3 = 1
ADCIN 0, adval ' A/D 8 bit value from PORTA.0 into adval
HSEROUT [adval] ' Output ASCII character rep of word serially to PC from C.6
horizpulse = horizpulse + 1
IF horizpulse < 784 THEN
GOTO horizloop
ELSE
PAUSEUS 820
GOTO vertloop
ENDIF
END
-
OK, well I figured out why I was getting weird readings on the logic analyzer... I was looking at the wrong (duplicate) channels, which is why I thought they (h1 and h2 and v1 and v2) were in phase instead of 180 degrees out of phase. So they work fine. Now, I think my only problem is that the chip cannot stop... It will wait for me to push the button on PORTB.5, but even after like 10 minutes, it will not stop (total time for transfer calculated to be about 2.5 minutes). Is there any reason why the loop structure would not be working?? Are the values to big for the stack (the counters i mean)? thanks again.