Triggering 5 TTL clocks simultaneously


Closed Thread
Results 1 to 40 of 84

Hybrid View

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


    Did you find this post helpful? Yes | No

    Default

    By polling INT0 flag bit... no interrupt handler
    Code:
        ' INT0 polling with PWM
        ' =====================
        '
        ' File name :  INT0_poll_PWM.bas
        ' Company : Mister E 
        ' Programmer : Steve Monfette
        ' Date : 02/03/2005
        ' Device : PIC18F2320
        '
        '
        ' This program generate 3.6Khz @ 25% duty PWM on CCP1 pin.
        '
        ' CCP1 pin is connected to RB0 pin via 1k resistor.
        '
        ' Program blink a led on PORTB.6 while generating PWM.
        ' Each rising edge of PWM, PORTB.7 is toggle.  This will 
        ' generate 1.8Khz 50% duty on this PORTB.7 pin.
        '
        ' We will check INTCON.1 (Interrupt on RB0(INT0) flag bit) pin to 
        ' detect rising edge
        
    
        ' Hardware Definition
        ' ===================
        '
        DEFINE LOADER_USED 1
        DEFINE OSC 20
        
        TRISB=%00000001   ' PORTB.0 as input
        TRISC.2=0         ' PORTC as output
        ADCON1=$0F        ' disable A/D converter
        
        ' Interrupt definition
        ' ====================
        '
        INTCON=%00010000  ' Disable global interrupts
                          ' Enable INT0 interrupt (RB0)
        
        INTCON2.6=1       ' Enable INT0 on rising edge
        
       
        ' Variable definition
        ' ===================
        '
        Tmr2dutyvar VAR WORD
        DelayLoop   var word
    
        ' PWM signal generation
        ' =====================
        '
        
        Tmr2dutyvar=86 ' load duty time duration
        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
        
    
        ' Main Loop
        ' =========
        '
        ' Stupid led blink on PORTB.6 while testing INT0 flag bit 
        '
    Start:
          toggle PORTB.6
          for delayloop = 1 to 50000
              pauseus 5 
              if INTCON.1 then
                 INTCON.1=0
                 toggle PORTB.7
              endif
                 
          next
          goto start
    Steve

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

  2. #2
    TurboLS's Avatar
    TurboLS Guest


    Did you find this post helpful? Yes | No

    Default

    Is there any reason why I can't get the process to start when PORTA.2 goes high?? I haven't rewired the HPWM/RB0 yet, but that should not matter. The PIC should at least shift the vertical clocks before even checking the reset (interrupt flag). Are my registers set correctly for analog input to PORTA.0 and digital input to PORTA.2??

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


    Did you find this post helpful? Yes | No

    Default

    to have analog on PORTA.0

    ADCON1=%00001110
    Steve

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

  4. #4
    TurboLS's Avatar
    TurboLS Guest


    Did you find this post helpful? Yes | No

    Default

    OK, well I think I got it working so that it waits for the push button to start, but then it seems like it keeps going even after the loops have completed. I will put in an LED command to signal when clocking is in progress and see what happens. It may just be that my calculations for transfer times are just off. I figured that at 3.6Khz sampling (which is how fast we would be sampling the real data), we could sample the data, do the A/D, and send the data off chip in about 2 minutes at 19200 inverted baud. Am I off in my estimations?

  5. #5
    TurboLS's Avatar
    TurboLS Guest


    Did you find this post helpful? Yes | No

    Default

    Again, I have about 350,000 samples to take and transfer off the PIC serially.

  6. #6
    TurboLS's Avatar
    TurboLS Guest


    Did you find this post helpful? Yes | No

    Default

    OK, I think I finally have everything working. I have an LED on bit 5 of portb the is low when the clocks are not running and hig when they are. I had had a problem with the switch on PORTA.2 floating high, so I put a 2 position switch between 5v and ground and that seemed to solve the problems. My next move is to hook up a logic analyzer to make sure all the clocks are synched up. Thanks guys for all your help and I'll let you know how it goes.

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


    Did you find this post helpful? Yes | No

    Default

    you don't really need that kind of switch.... place a pull-up or pull down resistor will do the job as well.

    For the logic analyser stuff... great idea if you have one. Case not, if you still have an analog scope, it's easy to build one with few CMOS components.
    Steve

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

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 : 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