PIC16F84A using pulsout and TMR0


Closed Thread
Results 1 to 33 of 33

Hybrid View

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


    Did you find this post helpful? Yes | No

    Default

    too bad PIC16F84a don't have 2 timers... The Henrik solution will work indeed, but i'll suggest to use shorter PAUSEUS, let's say 10uSec... OR a loop of @ nop.

    If you need accuracy, you may decide to fine-tune it using MPLAB stopwatch OR measure it using an extra i/o and a scope.

    Another solution... Use 2 variables, flags and 1 Timer.

    There's many different ways.
    Steve

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

  2. #2
    Join Date
    Nov 2006
    Posts
    33


    Did you find this post helpful? Yes | No

    Post Thanks for the reply....some question below....

    Hi all

    Thanks to HenrikOlsson and mister_e that give me the marvelous advice.
    I had tested it on the lab but the period is 4.6 and something 4.5. After I change it to For 0 To 2020 it will work 4.3 and something 4.2.
    I just measure it using stopwatch.
    For accuracy of the clock I will assign TMR0 = 12 {((fosc/4)*(256-12)*256)=0.9994}. Is that OK????

    Mister_e has suggest me to use 10us pause. Which mean that the for loop have to increase to 216000 rite???
    Sorry..I don't undestand the statement below:-

    *****If you need accuracy, you may decide to fine-tune it using MPLAB stopwatch OR measure it using an extra i/o and a scope.
    Another solution... Use 2 variables, flags and 1 Timer.*****************

  3. #3
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,605


    Did you find this post helpful? Yes | No

    Default

    Hi,
    I don't follow you on the math....
    If you reload TMR0 with 12 each interrupt you'll get (256-12) * 256 = 62464uS between each interrupt.

    What kind of accuracy do you need? With the prescaler set to 1:256 and a TMR0 reload value of 178 you'll get (256-178)*256 = 19968uS between each interrupt plus a little for the time it takes to reload.

    Another way would be to use an external xtal for TMR0, with a standard 32.768 watch xtal and the prescaler set to 1:128, you'll get one interrupt each second.

    MPLAB have a simulator where you can run the code, it has a stopwatch function that can be used to "measure" how long a certain piece of code takes. I've never used it myself.

    /Henrik Olsson.

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


    Did you find this post helpful? Yes | No

    Default

    Instead of using StopWatch, you may measure it in real-world. Use a scope and measure the time using an extra I/O.

    Example:

    High AextraIO
    ' code you need to evaluate
    LOW AextraIO

    You place your scope (or frequency meter, etc etc) on the AextraIO pin and you measure it.

    something handy for your Timer Calc
    http://mister-e.org/pages/utilitiespag.html
    Steve

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

  5. #5
    Join Date
    Nov 2006
    Posts
    33


    Did you find this post helpful? Yes | No

    Post store 365 data..

    Thanks to the advice and reply, I really appreciated it.

    From the interupt I know that I could add in the date.Such as day=day+1,month=month+1 and so on....

    I have another matter which is WHERE can i store 365 sunrsie time?
    My algoritm is just like that:-
    1 jan 2006 the sunrise time is 6:10 motor start run and 2 jan 2006 the sunrise time is 6:15 and so on.

    I know that it is impossible for me to store 365 data in the PIC16F84A eeprom.
    Can I store my data into the program memory or RAM?????

    Please advice and thanks you very much...

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


    Did you find this post helpful? Yes | No

    Default

    you could save it to the codespace and play around the following
    http://www.pbpgroup.com/modules/wfse...p?articleid=10

    or, use an external EEPROM.
    Steve

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

  7. #7
    Join Date
    Nov 2006
    Posts
    33


    Did you find this post helpful? Yes | No

    Post LCD question

    Hi all
    Thanks for the reply.

    Just now on the lab I have try to display the word in the LCD but NOT SUCCESS.
    Below is the code I follow all the connection on the PBP manual using PIC16F84A. LCD is bought from the www.cct.com.my.


    ‘ Set LCD Data port
    DEFINE LCD_DREG PORTA
    ‘ Set starting Data bit (0 or 4) if 4-bit bus
    DEFINE LCD_DBIT 0
    ‘ Set LCD Register Select port
    DEFINE LCD_RSREG PORTA
    ‘ Set LCD Register Select bit
    DEFINE LCD_RSBIT 4
    ‘ Set LCD Enable port
    DEFINE LCD_EREG PORTB
    ‘ Set LCD Enable bit
    DEFINE LCD_EBIT 3
    ‘ Set LCD bus size (4 or 8 bits)
    DEFINE LCD_BITS 4
    ‘ Set number of lines on LCD
    DEFINE LCD_LINES 2
    ‘ Set command delay time in us
    DEFINE LCD_COMMANDUS 2000
    ‘ Set data delay time in us

    Pause 100 ' Wait for LCD to startup
    LCDOut $fe, 1 ' Clear LCD screen
    LCDOut "Hello" ' Display Hello

    End

    Please advice and thanks

  8. #8
    Join Date
    Nov 2006
    Posts
    33


    Did you find this post helpful? Yes | No

    Post Some LCD stuff

    Hi all

    One question to ask...

    I actually want to display "Time: 00:00:00"
    The LCD is working but the problem is it is only happen when i use crystal 2.4576Mhz.

    When i change my crystal to 4Mhz it will just display "00:00:00"
    without seeing the word "Time"..
    I had add the pull up esistor to 1k ohm and DEFINE LCD_COMMANDUS 1000. Is that ok???

    Why??
    Does it need to pause more longer???


    Thanks
    Last edited by DragonBall_6; - 7th December 2006 at 13:38.

  9. #9
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,605


    Did you find this post helpful? Yes | No

    Default

    Hi,
    Do you have DEFINE LCD_COMMANDUS 1000 in your code? If that's the case try increasing that to 2000 to start with. If that doesn't help put a PAUSE 500 right at the beginning of the program, that will let the LCD startup for sure.

    If that doesn't help either, increase the COMMANDUS and DATAUS defines. Test with 10000 for COMMANDUS and 500 for DATAUS just to see if it helps. If it works, try to find the sweetspot just over where it stops working.

    /Henrik Olsson.

  10. #10
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by HenrikOlsson
    Hi,
    Do you have DEFINE LCD_COMMANDUS 1000 in your code? If that's the case try increasing that to 2000 to start with. If that doesn't help put a PAUSE 500 right at the beginning of the program, that will let the LCD startup for sure.

    If that doesn't help either, increase the COMMANDUS and DATAUS defines. Test with 10000 for COMMANDUS and 500 for DATAUS just to see if it helps. If it works, try to find the sweetspot just over where it stops working.

    /Henrik Olsson.

    Unless PBP has been fixed, I seem to remember that the DATAUS define was actually a byte define. In other words, if you specify DATAUS 257, it'll actually come out to be DATAUS 1. I could be wrong. The COMMANDUS is still a word define. I'll check a .lst file when I get home tonight to confirm that.
    JDG

  11. #11
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,605


    Did you find this post helpful? Yes | No

    Default

    Hi Skimask,
    Thank you! I didn't know about that. Please let us know what you find out!

    /Henrik Olsson.

  12. #12
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by HenrikOlsson
    Hi Skimask,
    Thank you! I didn't know about that. Please let us know what you find out!

    /Henrik Olsson.


    I just checked it out.
    If you look in any .lst file that contains any LCD defines or usage, you'll see that the LCD_COMMANDUS is a word variable internal to PBP and, as I suspected, LCD_DATAUS is a byte variable internal to PBP. So, you can't use anything higher than 255 in LCD_DATAUS.
    Another thing to be changed in upcoming PBP manuals...
    JDG

Similar Threads

  1. Pin won't stay high during Repeat...Until loop??
    By jellis00 in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 16th August 2009, 23:57
  2. Won't go back to SLEEP after 1st Interrupt
    By jellis00 in forum mel PIC BASIC Pro
    Replies: 32
    Last Post: - 29th June 2009, 09:00
  3. Battery powered applications
    By NavMicroSystems in forum Off Topic
    Replies: 7
    Last Post: - 22nd June 2009, 07:12
  4. COUNT is not counting again
    By jellis00 in forum mel PIC BASIC Pro
    Replies: 33
    Last Post: - 19th June 2009, 04:52
  5. Can't ID interrupt source with this IntHandler??
    By jellis00 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 3rd June 2009, 02:35

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