• AVR Freaks

Hot!One Shot mode for PIC18

Author
fsonnichsen
Super Member
  • Total Posts : 330
  • Reward points : 0
  • Joined: 2009/08/13 11:00:11
  • Location: 0
  • Status: offline
2021/01/24 14:46:20 (permalink)
0

One Shot mode for PIC18

PIC18LF44K22 
I have used various TMR and CCP functions for PWM and signal timing but I am confronted with a simple task--to issue a pulse (or inverse pulse) of a fixed length.
  > the start of the pulse is not particularly important. It is started at some point from my software
  > the length of the pulse--when it ends--IS important. I need to specify that it ends 100usecs from the start for example. (not too concerned with jitter here)
This is basically the function of a multi-vibrator or 1-shot.
 
I think there was a PIC in the past that actually had/has a one-shot mode but I am using the PIC18LF44K22 which does not. 
I can conceive of some contrivances using interrupts, re-routing the output trigger pin from Compare etc but I would think there is a much simpler way to do this. (I do not want latency introduced by interrupts or program control of the pins).
 
Any help appreciated
Fritz
#1

4 Replies Related Threads

    Jim Nickerson
    User 452
    • Total Posts : 6933
    • Reward points : 0
    • Joined: 2003/11/07 12:35:10
    • Location: San Diego, CA
    • Status: offline
    Re: One Shot mode for PIC18 2021/01/24 14:49:32 (permalink)
    0 (2)
    One shot mode, asked once is enough.
    #2
    NorthGuy
    Super Member
    • Total Posts : 6597
    • Reward points : 0
    • Joined: 2014/02/23 14:23:23
    • Location: Northern Canada
    • Status: offline
    Re: One Shot mode for PIC18 2021/01/24 15:11:18 (permalink)
    +1 (1)
    Just disable CCP after it produced the shot.
    #3
    davea
    Super Member
    • Total Posts : 644
    • Reward points : 0
    • Joined: 2016/01/28 13:12:13
    • Location: Tampa Bay FL USA
    • Status: offline
    Re: One Shot mode for PIC18 2021/01/24 18:36:45 (permalink)
    0
    I think there was a PIC in the past that actually had/has a one-shot mode but I am using the PIC18LF44K22

    Yes, 
    TIMER2 MODULE WITH
    HARDWARE LIMIT TIMER (HLT)
     
     
    20.0 SR LATCH
    The module consists of a single SR latch with multiple
    Set and Reset inputs as well as separate latch outputs.
    The SR latch module includes the following features:
    • Programmable input selection
    • SR latch output is available internally/externally
    • Selectable Q and Q output
    • Firmware Set and Reset
    The SR latch can be used in a variety of analog
    applications, including oscillator circuits, one-shot
    circuit, hysteretic controllers, and analog timing
    applications.
    post edited by davea - 2021/01/24 18:39:34
    #4
    fsonnichsen
    Super Member
    • Total Posts : 330
    • Reward points : 0
    • Joined: 2009/08/13 11:00:11
    • Location: 0
    • Status: offline
    Re: One Shot mode for PIC18 2021/01/30 14:22:09 (permalink)
    0
    Dave- Looks like the SR Latch limits pulse width to 2 Tosc. At any rate I was unaware of this function and could be useful later-Thanks!
     
    SO along lines similar to NorthGuy--
       I start with the CCP4 and TMR off. 
       Zero the TMR and set up the pulse duration in CCP4. 
       Start CCP4 in "clear" mode - this raises the start of the pulse.
       Write a start to the TMR enable bit immediately. The time is negligible between these 2 steps
    This runs until the TMR matches the duration. I note that a value of "1" for the clock cycle for the duration gives a pulse of zero and so forth.
     
    Rather drawn out way to send a defined pulse but it is the only way I could think of with the tools at hand.
    cheers and thanks all-
    fritz
     
    ================ CODE SNIP ===============================
    TMR1_StopTimer(); //Stop timer
    CCP4CON = 0x00; //reset CCP4. This resets CCP pin as well
    TMR1_WriteTimer(0x0000); //Timer starts at zero
    CCP4_SetCompareCount(duration_TMR);

    __delay_ms(1000); //delay to view scope shot

    CCP4CON = 0x09; //set CCP to COMPARE and to CLEAR upon match
    // TMR1_StartTimer(); //dont use TMR1_StartTimer() as it costs about 500ns
    T1CONbits.TMR1ON = 1; // use direct start of TMR1

    __delay_ms(1000); //delay to view scope shot

    while( CCP4_IsCompareComplete() == false); //wait for CCP4 to trigger after duration
    #5
    Jump to:
    © 2021 APG vNext Commercial Version 4.5