how to generate two signals from two ports at the same time by using p16f84


Closed Thread
Results 1 to 27 of 27

Hybrid View

  1. #1
    Join Date
    Jul 2011
    Posts
    17


    Did you find this post helpful? Yes | No

    Default Re: how to generate two signals from two ports at the same time by using p16f84

    yes, i have tried it also, i put them in main loop but i could not obtain time accuracy.

  2. #2
    Join Date
    Jul 2011
    Posts
    17


    Did you find this post helpful? Yes | No

    Default Re: how to generate two signals from two ports at the same time by using p16f84

    i need a loop with constant 8 mic. sec. time period and multiplying it with two different variables to obtain to different signal. but how?

  3. #3
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default Re: how to generate two signals from two ports at the same time by using p16f84

    How fast are you allowed to run the MCU?
    Dave
    Always wear safety glasses while programming.

  4. #4
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default Re: how to generate two signals from two ports at the same time by using p16f84

    Dave
    Always wear safety glasses while programming.

  5. #5
    Join Date
    Jul 2011
    Posts
    17


    Did you find this post helpful? Yes | No

    Default Re: how to generate two signals from two ports at the same time by using p16f84

    i am allowed to use pic16f84 and 10 mhz crystal. i think this project is impossible, since i have struggled so much, but unfortunately he has a circuit doing that with pic16f84 :0

  6. #6
    Join Date
    Jul 2011
    Posts
    17


    Did you find this post helpful? Yes | No

    Default Re: how to generate two signals from two ports at the same time by using p16f84

    thanks a lot mackrackit

    that utility makes me more careful about timer. now let me review my program again

  7. #7
    Join Date
    Aug 2010
    Location
    Maryland, USA
    Posts
    869


    Did you find this post helpful? Yes | No

    Default Re: how to generate two signals from two ports at the same time by using p16f84

    Your first post said you needed to be able to select 2 frequencies. How are they selected? If they are just hardcoded in and there is nothing in the "main", there is no need for an interrupt. You can do it all from the main routine. This will save all the time required to process the interrupt.your code would have 1 line looking for the timer overflow such as :
    Code:
    while !tmr0 overflow
    wend
    then load 2 counters, 1 for each output
    Code:
    freq1 = period / timer0
    freq2 = period2 / timer0
    then on each overflow, decrement the freq's. when 1 reaches zero
    Code:
    if !freq then
     toggle output bit
     reload freq
    endif
    now don't forget to reload the timer unless you can set it up to just free run. You will need to play with the freq's counter numbers to "tune" the output, but I suspect you can get it right on the money.
    -Bert

    The glass is not half full or half empty, Its twice as big as needed for the job!

    http://foamcasualty.com/ - Warbird R/C scratch building with foam!

  8. #8
    Join Date
    Jul 2011
    Posts
    17


    Did you find this post helpful? Yes | No

    Default Re: how to generate two signals from two ports at the same time by using p16f84

    hi cncmachineguy

    dividing two variables by tmr0 and obtaining two periods from tmr0, it seems to work, but i think there can be some problems. for example, should we reload tmr0 with respect to which signal? for the first pulses ok but then when next period start?

    program below is what you said, isn't it? thank you for advices

    Code:
        OPTION_REG=%00000000
        TMR0=0
        INTCON=%10100000
    main:
        while   tmr0>=250 
        tmr0= 0
        wend
          
        freq1= per1 / timer0
        freq2= per2 / timer0
        
        if  freq1<1 then    
        toggle  a0
        per1=100
        else
        endif
        
        if  freq2<1 then    
        toggle  a0
        per2=200
        else
        endif
        goto    main

Members who have read this thread : 0

You do not have permission to view the list of names.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts