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

    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.

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

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

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

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

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

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

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