Triggering 5 TTL clocks simultaneously


Closed Thread
Page 1 of 3 123 LastLast
Results 1 to 40 of 84
  1. #1
    TurboLS's Avatar
    TurboLS Guest

    Default Triggering 5 TTL clocks simultaneously

    OK, this code is written to wait for an interrupt, then clock out 784x512 bytes of data. The only chunk of the code shown is that which controls the clocking scheme. My question is if there is any way to execute time sensitive commands faster than the 1 usec instruction time. Thanks for all the help.

    horizpulse var byte
    vertpulse var byte

    horizpulse = 1
    vertpulse = 1
    PORTB.0 = 0 ‘portb.0 is the Vphase1 clock
    PORTB.1 = 0 ‘portb.1 is the Vphase2 clock
    PORTB.2 = 1 ‘portb.2 is the Hphase1 clock
    PORTB.3 = 0 ‘portb.3 is the Hphase2 clock
    PORTB.4 = ‘portb.4 is the reset clock

    buttonloop:
    IF PushButtonOnPORTABIT2 = 1
    THEN GOTO vertloop ‘waits for 5V that signals shutter is closed
    ELSE GOTO buttonloop
    vertloop:
    horizpulse = 1
    PORTB.0 = 1
    PAUSEUS 139
    PORTB.0 = 0
    PORTB.1 = 1
    PAUSEUS 139
    PORTB.0 = 1
    PORTB.1 = 0
    PAUSEUS 139
    PORTB.0 = 0
    PAUSEUS 270
    vertpulse = vertpulse + 1
    IF vertpulse < 512
    THEN GOTO horizloop
    ELSE GOTO buttonloop
    horizloop:
    PORTB.2 = 0
    PORTB.3 = 1
    PAUSEUS 139
    PORTB.3 = 0
    PORTB.2 = 1
    PAUSEUS 139
    horizpulse = horizpulse + 1
    IF horizpulse < 784
    THEN GOTO horizloop
    ELSE GOTO vertloop
    END

  2. #2
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    My question is if there is any way to execute time sensitive commands faster than the 1 usec instruction time
    use a faster crystal.. depending of your PIC... some can run up to 40MHZ.

    so in this case... 0.1 usec by SOME ASSEMBLER instruction
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  3. #3
    TurboLS's Avatar
    TurboLS Guest


    Did you find this post helpful? Yes | No

    Default

    I was also toying with the idea of just setting the registers in one line, like

    PORTA = %11001010

    or something to that effect, but I have no idea how I would loop that.

  4. #4
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    if you want to send 8 bits of data to PORTA in one shot... yes PORTA=MydataToSend will be what you need. Be sure that you have set the TRISA register before that
    TRISA=255
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  5. #5
    TurboLS's Avatar
    TurboLS Guest


    Did you find this post helpful? Yes | No

    Default

    Ok, here is my updated code, now I just have a few questions:

    1.) Is there a way to split PORTA into analog and digital inputs?
    2.) PORTB.4 is the reset clock and basically it has to be pulsing as soon as the microcontroller powers up. The problem is that once i start the other clocks, the time at which the reset goes high has to be in synch with H1 going low and H2 going high. In addition, it's high duration is 1/4 of the high time of the horizontal clocks. I will post up a timing diagram to explain what i mean later today. So basically I can't just put it in one of my loops, I have to start it pulsing at like a 25% duty cycle and when the other clocks are going, it has to be in synch with the horiztonals like i said earlier.

    any help is appreciated.

    ' Connect analog input to (RA0)
    ' Connect clocks to PORTB
    ' PORTB.0 is the Vphase1 clock
    ' PORTB.1 is the Vphase2 clock
    ' PORTB.2 is the Hphase1 clock
    ' PORTB.3 is the Hphase2 clock
    ' PORTB.4 is the reset clock
    ' 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

    TRISA = %11111111 ' Set PORTA to all input
    ADCON1 = %00000010 ' Set PORTA analog
    TRISB = %00000000 ' Set PORTB to all output
    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.0 = 0
    PORTB.1 = 0
    PORTB.2 = 1
    PORTB.3 = 0
    PORTB.4 = 0

    buttonloop:
    IF PushButtonOnPORTABIT2 = 1
    THEN GOTO vertloop ' Waits for 5V that signals shutter is closed
    ELSE GOTO buttonloop
    vertloop:
    horizpulse = 1
    PORTB.0 = 1
    PAUSEUS 139
    PORTB.0 = 0
    PORTB.1 = 1
    PAUSEUS 139
    PORTB.0 = 1
    PORTB.1 = 0
    PAUSEUS 139
    PORTB.0 = 0
    PAUSEUS 270
    vertpulse = vertpulse + 1
    IF vertpulse < 512
    THEN GOTO horizloop
    ELSE GOTO buttonloop
    horizloop:
    PORTB.2 = 0
    PORTB.3 = 1
    PAUSEUS 139
    PORTB.3 = 0
    PORTB.2 = 1
    PAUSEUS 50
    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
    PAUSE 87
    horizpulse = horizpulse + 1
    IF horizpulse < 784
    THEN GOTO horizloop
    ELSE GOTO vertloop
    END
    Last edited by TurboLS; - 21st February 2005 at 21:37. Reason: incomplete

  6. #6
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    1.) Is there a way to split PORTA into analog and digital inputs?
    for sure... see datasheet in the A/D section.. ADCON1 TABLE 19-2

    will be interesting to have kind of flowchart and schematic for the other problems you have.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  7. #7
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    TurboLS,

    What version of PBP are you using? I've never seen this work in any versions I've had.

    IF vertpulse < 512
    THEN GOTO horizloop
    ELSE GOTO buttonloop

    I've wanted to use that type of syntax before, but I get nothing but errors. Did I miss an update or something. I have 2.45

    Darrel
    DT

  8. #8
    TurboLS's Avatar
    TurboLS Guest


    Did you find this post helpful? Yes | No

    Default

    I am using 2.46 and I will have a pic up soon that has the timing scheme. thanks for the replies.

  9. #9
    TurboLS's Avatar
    TurboLS Guest


    Did you find this post helpful? Yes | No

    Default

    here is the timing diagram. notice how the reset, H1, and H2 are in synch at the lower right. Also notice that the reset is going all the time, even when the other 4 clocks are not.

    please click the link and scroll to page 13

    http://www.kodak.com/global/plugins/...2ELongSpec.pdf

    thanks.
    Last edited by TurboLS; - 21st February 2005 at 22:56.

  10. #10
    TurboLS's Avatar
    TurboLS Guest


    Did you find this post helpful? Yes | No

    Default

    Oh yeah, i am gettin some errors from that if else stuff too.... gonna have to find a way around that arghhhh!

    scratch that, you just have to put all the commands on the same line, like so:

    IF vertpulse < 512 THEN GOTO horizloop ELSE GOTO buttonloop

    however, i still have 9 errors to fix before mine compiles properly.
    Last edited by TurboLS; - 21st February 2005 at 23:13.

  11. #11
    TurboLS's Avatar
    TurboLS Guest


    Did you find this post helpful? Yes | No

    Default

    Also, I tried looking at the ADCON1 register, and i guess if I am reading from the table properly... to set PORTA.2 to digital in, I should say ADCON1 = %00001101 cuz that's where the D and the AN2 meet.

    I am still having a problem with the OnPushButton command and apparently I have to use END IF commands, which I am not sure how I will implement just yet.

  12. #12
    TurboLS's Avatar
    TurboLS Guest


    Did you find this post helpful? Yes | No

    Default

    I got it down to 6 errors, all with my IF statements. Here is what I have for a generic IF line:

    IF PushButtonOnPORTABIT2 = 1 THEN GOTO vertloop ELSE GOTO buttonloop

    on the following line i have

    ENDIF

    and doing that got rid of 3 of the errors, but now I need to figure out why it doesn't like my then goto / else goto commands.

    For each of my 3 if statements, I get

    bad expression
    bad expression or missing then
    Last edited by TurboLS; - 21st February 2005 at 23:53.

  13. #13
    TurboLS's Avatar
    TurboLS Guest


    Did you find this post helpful? Yes | No

    Default

    OK, i know i have been posting a lot lately, but now i am down to 2 errors, both associated with

    IF PushButtonOnPORTABIT2 = 1 then

    I think it has something to do with me setting the ADCON1 register incorrectly.

  14. #14
    TurboLS's Avatar
    TurboLS Guest


    Did you find this post helpful? Yes | No

    Default

    OK, I fixed it (I think) to where I have no compiler errors.

    basically I had to change the above line to

    IF PORTA.2 = 1 then

  15. #15
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    IF vertpulse < 512 THEN GOTO horizloop ELSE GOTO buttonloop
    I prefer like this

    Code:
    IF vertpulse < 512 THEN 
        GOTO horizloop 
    ELSE 
        GOTO buttonloop
    ENDIF
    Using Alias to i/o
    Code:
    TRISA = 255 ' Set PORTA as input
    
    PushButton1 var PORTA.0
    PushButton2 var PORTA.1
    PushButton3 var PORTA.2
    
    IF PushButton1 then ' Same as PushButton=1
       ' do your stuff here
    ENDIF
    Last edited by mister_e; - 22nd February 2005 at 00:37.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  16. #16
    TurboLS's Avatar
    TurboLS Guest


    Did you find this post helpful? Yes | No

    Default

    So yeah I am still stuck with the whole reset clock thing. Is there a way I can generate a clock in hardware that is not a 50% duty cycle? By using one of the timer functions perhaps?

    I was also wondering approximately how fast each of the commands in my program would take to process. Knowing that, I would be able to generate the reset clock by estimating the time in usecs.

    thanks again for all the input.
    Last edited by TurboLS; - 22nd February 2005 at 03:37.

  17. #17
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    One thing i figure is to use the OSCLKO pin and connect to RB0 or else interrupt source. Once you'll be the in the interrupt routine, you'll be able to do everything. Generate all your delay and pin level. Will be a bit tricky to get the perfect timing but not impossible.

    If you want to generate a 4MHZ clock, you'll need a 8MHZ crystal. Interrupt on rising or falling edge. Interrupt routine will generate your R, H1 and H2 frequency in one shot.

    Depending your crystal speed, your instruction will be executed in few msec or less.

    BUT for that kind of stuff where accuracy and precision is important, you'll probably need to do your delay and some test in assembler. Assembler instruction can be executed in 1 or 2 frequency cyle. Let's say at 8MHZ, 1 intruction every (1/(8Mhz/4)) = 0.5 uSec. Can be usefull to have a PIC who have an internal PLL to multiply your cystal speed.

    If you have a 8MHZ crystal, execution time will be 4 times faster so from 0.5uSec to 0.125 uSec.
    Last edited by mister_e; - 22nd February 2005 at 03:49.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  18. #18
    TurboLS's Avatar
    TurboLS Guest


    Did you find this post helpful? Yes | No

    Default

    The reset, H2, and H1 will be about 3.6kHz. I don't know if there is a way I can get that with the multipliers.

    Is there like a table where I can calculate the execution times? I know that "time-sensitive" commands take 1 usec with a 20Mhz clock (which is what I am using).

    How long do if statements and such take, jumps to different parts of the program (like when I use the GOTO commands)?

  19. #19
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    if they are constant... you can use HPWM on 2 channel... 2 different duty but the same frequency. They will run in background and they will not be interfered by anything else.

    OR you can use the internal TIMER1 16bit and do you delay stuff when you get TIMER1 overflow interrupt.

    at 3.6 KHZ period = 277.777 uSec

    let's say you'll use a 20Mhz crystal... internal frequency 5MHZ period = 0.2 uSec = 1388.888 internal clock count. We want to change state every 1/2 period. 1388.888 uSec / 2 = 694.4444 uSec. So you'll have to preload Timer1 to 65535-694 = 64841 or $FD49.

    here's a snippet to produce 3 different duty cycle with TIMER1
    Code:
    ' program to generate Multiple duty cycle @ 5 mhz on PORTC
    ' Use of PIC18F2220
    '
    @ __CONFIG _CONFIG1H, _HS_OSC_1H 
        '  HS 
    
    @ __CONFIG _CONFIG2L, _BORV_20_2L & _BOR_ON_2L & _PWRT_ON_2L
        '  BOR Voltage - 2.0v
        '  Brown-Out Reset enabled
        '  Power-Up Timer enabled
        
    @ __CONFIG _CONFIG2H, _WDT_ON_2H
        '  Watch Dog Timer enabled
    
    @ __CONFIG _CONFIG3H, _MCLRE_ON_3H & _PBAD_DIG_3H & _CCP2MX_ON_3H & _CCP2MX_B3_3H
        '  MCLR enabled
        '  PORTB<4:0> pins reset as digital pins
        '  CCP2 pin function on RC1
        '  CCP2 pin function on RB3 (alt defn)
    
    @ __CONFIG _CONFIG4L, _DEBUG_OFF_4L & _LVP_OFF_4L & _STVR_ON_4L
        '  DEBUGger disabled
        '  Low Voltage Prgramming disabled
        '  Stack over/underflow Reset enabled
    
    @ __CONFIG _CONFIG5L, _CP0_OFF_5L & _CP1_OFF_5L
        '  Block 0 readable/ may be writable 
        '  Block 1 readable/ may be writable
    
    @ __CONFIG _CONFIG5H, _CPB_OFF_5H & _CPD_OFF_5H
        '  Boot Block readable / may be writable 
        '  Data EE memory readable / may be writable
    
    @ __CONFIG _CONFIG6L, _WRT0_OFF_6L  & _WRT1_OFF_6L
        '  Block 0 writable
        '  Block 1 writable
    
    @ __CONFIG _CONFIG6H, _WRTC_OFF_6H & _WRTB_OFF_6H & _WRTD_OFF_6H
        '  Config registers writable
        '  Boot block writable
        '  Data EE writable 
    
    @ __CONFIG _CONFIG7L, _EBTR0_OFF_7L & _EBTR1_OFF_7L
        '  Block 0 readable
        '  Block 1 readable
    
    @ __CONFIG _CONFIG7H, _EBTRB_OFF_7H
        '  Boot block readable
        
        DEFINE OSC 20 
        TRISC=0
        INTCON = %01000000 ' enable peripheral interrupt
        PIE1 = %00000001   ' enable TIMER1 overflow interrupt
    	TMR1L=$49
    	TMR1H=$FD
        T1CON = %00000101 ' prescaler 1:1
        				  ' Clock source = Fosc/4
        				  ' start the timer1
        on interrupt goto TMR1_Overflow
        Passes	var	bit
        clear
    START: 
        goto start
        
    disable
    TMR1_Overflow:
        T1CON.0=0 'stop timer
        PIR1.0=0 ' reset interrupt flag
        TMR1l=$49
    	TMR1H=$FD
        T1CON.0=1 'start timer
    	if Passes then
        	PORTC = 6
        	pauseus 69
        	PORTC = 4
        	passes= 0
    	else
           	PORTC = 1
        	passes= 1
        endif
        resume
    enable
    you may need to adjust the value of the TIMR1L to fine tune your frequency.

    To calculate or to know the time an instruction take, you can use MPLAB's stopwatch... give a great aprox of the time.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  20. #20
    TurboLS's Avatar
    TurboLS Guest


    Did you find this post helpful? Yes | No

    Default

    I was thinking of doing the reset on one of those HWPM things because the reset is the only constant clock. Then I could just do a conditional statement to make sure that the reset and the horizontal clocks are in synch. The good thing about that, like you said, it would run in the background and so I could run all the other clocks just as I had them. What do you think??

  21. #21
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Then I could just do a conditional statement to make sure that the reset and the horizontal clocks are in synch
    mmm, IMO you can't check with internal to synchronize them. I figure you'll have to use an extra i/o to read from the PWM output. Once you get the highlevel or interrupt, you do your Horizontal stuff. A microsecond or less of
    delay between to rising edge of Reset and your Horizontal... but at 3.6KHZ i can't figure it will be a big problem.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  22. #22
    TurboLS's Avatar
    TurboLS Guest


    Did you find this post helpful? Yes | No

    Default

    So you're saying something like:

    IF PWM output is high, start the horizontal clocks

    Yeah, using another I/O pin is not a problem, cuz at this point i think i am using 2 pins of portA

    How would I go about getting the HPWM to oscillate at 3.6kHz with a 25% duty cycle? I will look at the manual again later today or tomorrow probably and see if i can figure it out.

    thanks again, you are a huge help.

  23. #23
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    it's a bit more than if pin is high... IF the according pin is at the rising edge of the signal... this ensure the right timing. Use interrupt source INT0, INT1 or else you can have on the rising edge... will be really easy now. The only thing you have to care about is the timing and latency in the other routines to get interrupt as quick as possible.

    For the HPWM frequency and duty cycle, try

    HPWM 1,64,3600 ' supposed to send HPWM 3.6KHZ at 25% duty

    i don't know how accurate it will be. In my purpose i always set all the register myself. In your datasheet they tell you how to calculate everything.
    Last edited by mister_e; - 22nd February 2005 at 19:29.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  24. #24
    TurboLS's Avatar
    TurboLS Guest


    Did you find this post helpful? Yes | No

    Default

    What pin would that HPWM be coming off of??

  25. #25
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    HPWM channel = CCP1 of your 18F4520 = PIN RC2 PIN 17
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  26. #26
    TurboLS's Avatar
    TurboLS Guest


    Did you find this post helpful? Yes | No

    Default

    So I guess I could have it running in the background, then when I want to start the horizontal clocks, I could do an ON INTERRUPT command to make sure it is on the rising edge of the Reset HWPM clock.

  27. #27
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    you don't have to make sure it's on the rising edge. Interrupt will do it for you. When you set your interrupt you can select rising or falling edge.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  28. #28
    TurboLS's Avatar
    TurboLS Guest


    Did you find this post helpful? Yes | No

    Default

    And I set that in the registers, right? And then I can run a wire from PIN 17 to an interrupt pin and do an ON INTERRUPT command? Would it look something like this or totally different? I am going to try and find some examples.

    horizloop:
    ON INTERRUPT
    PORTB.2 = 0
    PORTB.3 = 1
    PAUSEUS 139
    PORTB.3 = 0
    PORTB.2 = 1
    PAUSEUS 50
    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
    PAUSE 87
    horizpulse = horizpulse + 1
    IF horizpulse < 784

  29. #29
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    NOP...

    i'll have more spare time tomorrow for that... BUT have a look on this thread download the code i did. It use the interrupt on an pin to do specific task. Can be handy to start. Code is well documented.

    ON INTERRUPT GOTO define the place to go when an intterupt happen. See PBP manual on that statement. care will have to be made in the interrupt routine too. sould not be too loang... at minimum less than the time between each interrupts.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  30. #30
    TurboLS's Avatar
    TurboLS Guest


    Did you find this post helpful? Yes | No

    Default

    Well I would think I would only need one in the loop, just to make sure the Reset(HWPM) and Horizontal 2 are on their rising edge as in synch as possible.

  31. #31
    TurboLS's Avatar
    TurboLS Guest


    Did you find this post helpful? Yes | No

    Default

    What if I did something like this??

    horizloop:
    PORTB.2 = 0
    PORTB.3 = 1
    PAUSEUS 139
    ENABLE
    ON INTERRUPT GOTO H2lock
    DISABLE
    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

    H2lock:
    PORTB.3 = 0
    PORTB.2 = 1
    RESUME

  32. #32
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    NOP, On Interruot goto is placed at the header of your code before your main loop. Since it's working in background, it will jump by himself to the interrupt routine. did you look at my previous link?

    INTCON and probably others have to be set for interrupt type/source.

    i'll make something like this later today.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  33. #33
    TurboLS's Avatar
    TurboLS Guest


    Did you find this post helpful? Yes | No

    Default

    What do you think of something like this>?

    ' Connect analog input to (RA0)
    ' Connect clocks to PORTB
    ' PORTB.0 is the Vphase1 clock
    ' PORTB.1 is the Vphase2 clock
    ' PORTB.2 is the Hphase1 clock
    ' PORTB.3 is the Hphase2 clock
    ' PORTB.4 is the reset clock
    ' 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

    ON INTERRUPT GOTO H2lock ' When Reset clock is high
    INTCON1 = %1001000 ' Enable RB0 Interrupt
    INTCON = $80 ' Disables Interrupts
    TRISA = %11111111 ' Set PORTA to all input
    ADCON1 = %00001101 ' Set PORTA analog, except for pin 2
    TRISB = %00000000 ' Set PORTB to all output
    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.0 = 0
    PORTB.1 = 0
    PORTB.2 = 1
    PORTB.3 = 0
    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.0 = 1
    PAUSEUS 139
    PORTB.0 = 0
    PORTB.1 = 1
    PAUSEUS 139
    PORTB.0 = 1
    PORTB.1 = 0
    PAUSEUS 139
    PORTB.0 = 0
    PAUSEUS 270
    vertpulse = vertpulse + 1
    IF vertpulse < 512 THEN
    GOTO horizloop
    ELSE
    GOTO buttonloop
    ENDIF
    horizloop:
    PORTB.2 = 0
    PORTB.3 = 1
    PAUSEUS 139
    INTCON = $80 ' Re-enables interrupts
    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

    DISABLE
    H2lock:
    PORTB.3 = 0
    PORTB.2 = 1
    RESUME
    ENABLE
    END

  34. #34
    TurboLS's Avatar
    TurboLS Guest


    Did you find this post helpful? Yes | No

    Default

    Also, I saw a blurb in the PBP manual about the fact that I can check the interrupt flag without actually enabling interrupts. If I did it that way, then I could merely do a check condition statement, similar to this, right?:

    IF PORTB.2 = 1 AND INTERRUPTFLAG = 1 ' When horizontal 1 is high and reset is high

    ' Do the H1 > low, H2 > high, ADC conversion and the SEROUT2

  35. #35
    TurboLS's Avatar
    TurboLS Guest


    Did you find this post helpful? Yes | No

    Default

    OK, I checked the datasheet and the interrupt flag bit is bit 1 of the INTCON register. It also says that I have to reset it in software once an interrupt has occurred. So I was thinking if I just set the INTCON.1 = 0 right before the condition statement, then I could just wait until the INTCON.1 = 1 before clocking the horizontals. What do you think?

  36. #36
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    Yep. I do this all the time.

    Disable global interrupts (INTCON.7 = 0), and just monitor & reset interrupt flags as needed. Very handy.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  37. #37
    TurboLS's Avatar
    TurboLS Guest


    Did you find this post helpful? Yes | No

    Default

    Should I still enable the INTCON1 register? I have it set to %1001000 to use the RB0 interrupt. I have the HWPM (which is to be the interrupt source) set as follows:

    HPWM 1,64,3600 ' Supposed to send HPWM 3.6KHZ at 25% duty

  38. #38
    TurboLS's Avatar
    TurboLS Guest


    Did you find this post helpful? Yes | No

    Default

    I tried compiling that and I get

    Symbol not previously defined (INTCON1)

    The updated code is as follows:

    ' Connect analog input to (RA0)
    ' Connect clocks to PORTB
    ' PORTB.0 is the Vphase1 clock
    ' PORTB.1 is the Vphase2 clock
    ' PORTB.2 is the Hphase1 clock
    ' PORTB.3 is the Hphase2 clock
    ' The reset will be connected to a HWPM clock pin #17
    ' 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

    INTCON1 = %1001000 ' Enable RB0 Interrupt
    INTCON.7 = 0 ' Disables global interrupts
    TRISA = %11111111 ' Set PORTA to all input
    ADCON1 = %00001101 ' Set PORTA analog, except for pin 2
    TRISB = %00000000 ' Set PORTB to all output
    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.0 = 0
    PORTB.1 = 0
    PORTB.2 = 1
    PORTB.3 = 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.0 = 1
    PAUSEUS 139
    PORTB.0 = 0
    PORTB.1 = 1
    PAUSEUS 139
    PORTB.0 = 1
    PORTB.1 = 0
    PAUSEUS 139
    PORTB.0 = 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
    PAUSEUS 2 ' the PORTB.2 goes low and
    IF INTCON.1 = 0 THEN ' PORTB.3 goes high as close
    GOTO Resetcheck ' to the external trigger's
    ELSE ' rising edge as possible
    ENDIF
    PORTB.2 = 0
    PORTB.3 = 1
    PAUSEUS 139
    PORTB.3 = 0
    PORTB.2 = 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

  39. #39
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    There is no INTCON1 register. That would be why you get the error. Look at your datasheet.

    To monitor interrupt "flag bits" you do not need to enable any interrupt enable bits or global interrupts.

    Any event or condition that will trigger the interrupt, will set the interrupts flag bit. This happens regardless of whether you have "any" interrupt enabled or disabled.

    A "Flag bit" indicates that an interrupt event occurred.

    The interrupt "Enable bit" allows program execution to branch to the interrupt vector address (if global interrupts are enabled) when the flag bit is set by the event that caused the interrupt.

    You can setup the RB0/INT0 on the 18F4520 to set the interrupt flag bit on a low-to-high or high-to-low transition on RB0/INT0. See the datasheet under INTCON2.

    Then all you need to do is monitor INTCON.1 (this means INTCON register bit #1 NOT INTCON1) which is the "flag bit" inidicating the transition (event) on RB0/INT0 has occured.

    After reading this bit, then reset it (clear it to 0) so you can check it again later to see if the event has happend again.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  40. #40
    TurboLS's Avatar
    TurboLS Guest


    Did you find this post helpful? Yes | No

    Default

    OK, I checked the manual and bit 6 controls the external 0 flag. I set it to '1' for the rising edge.

    INTCON2 = %0100000 ' External Interrupt Flag on Rising Edge

    Do I have to set the PORTB pull up enable bit?

    Also, RB0 will be read as an input (wired from the HWPM pin 17), so I will have to reconfigure my TRISB register to accept an input on PORTB, right?

    thanks again for the help.

Similar Threads

  1. PICs can do more if use others than delays instructions
    By hardcore in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 24th February 2010, 19:52
  2. How do I set GPIO 0-2 and 5 simultaneously?
    By cstack in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 19th August 2009, 09:32
  3. LCD will not start
    By btaylor in forum mel PIC BASIC Pro
    Replies: 49
    Last Post: - 24th May 2007, 02:30
  4. Replies: 11
    Last Post: - 13th July 2005, 19:26

Members who have read this thread : 1

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