Triggering 5 TTL clocks simultaneously


Closed Thread
Results 1 to 40 of 84

Hybrid View

  1. #1
    TurboLS's Avatar
    TurboLS Guest


    Did you find this post helpful? Yes | No

    Default

    So you are saying that my code is right and the pin is just acting weird? If it is burned, I have like 8 more PIC chips. I just want to make sure that the problem is fixed before I burn another one. So I will test this PORTB.0 with a simple blink program to see if it responds at all. I'll let you know what happens. Thanks again for your continued input.

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


    Did you find this post helpful? Yes | No

    Default

    Do the RB0 test before using others.

    BTW, i'm about setting up a board to do something like this for testing. ì'll post the code here.
    Steve

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

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


    Did you find this post helpful? Yes | No

    Default

    This one use RB0 interrupt handler routine.
    Code:
        ' INT0 with PWM
        ' =============
        '
        ' File name :  INT0_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 use Interrupt on RB0(INT0) 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=%10010000  ' Enable global interrupt
                          ' Enable INT0 interrupt (RB0)
        
        INTCON2.6=1       ' Enable INT0 on rising edge
        
        ON interrupt goto RB0_interrupt
        
        ' 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... 
        '
    Start:
          toggle PORTB.6
          for delayloop = 1 to 50000
              pauseus 5 
          next
          goto start     
    
    
        ' Interrupt routine
        ' =================
        ' 
        ' toggle PORTB.6 each rising edge on it.
        '  
    disable
    RB0_interrupt:
       toggle PORTB.7
       INTCON.1=0 ' reset INT0 interrupt flag
    resume
    enable
    Last edited by mister_e; - 3rd March 2005 at 04:32.
    Steve

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

  4. #4
    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.

  5. #5
    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??

  6. #6
    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.

  7. #7
    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?

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