1. Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
    Dismiss Notice

embedded program to store the value continuously

Discussion in 'Microcontrollers' started by fan174, Apr 12, 2018.

  1. fan174

    fan174 New Member

    Joined:
    Mar 13, 2018
    Messages:
    7
    Likes:
    0
    I want to determine time at every zero crossing for 5V AC input signal using the PIC micro-controller.

    How to write embedded program to store the value continuously like below table

     
  2. Nigel Goodwin

    Nigel Goodwin Super Moderator Most Helpful Member

    Joined:
    Nov 17, 2003
    Messages:
    39,504
    Likes:
    683
    Location:
    Derbyshire, UK
    Store it to what, and for how long?.
     
  3. fan174

    fan174 New Member

    Joined:
    Mar 13, 2018
    Messages:
    7
    Likes:
    0
    I want to store in variable T1, T2.. Tn in 8 bit data reading like the table I shown
     
  4. dave miyares

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    2
    Likes:
    -10


     
  5. jgharston

    jgharston New Member

    Joined:
    Dec 15, 2010
    Messages:
    17
    Likes:
    2
    Normally you'd store in an array as you can reference each entry by a number. What you're trying to do is reference differently-named variables. Ok if you have a small finite number of variables, but will rapidly get out of hand. Use an array:
    T[index]=data;
    Otherwise, you're looking at:
    switch(index)
    when 1: T1=data; break;
    when 2: T2=data; break;
    when 3: T3=data; break;
    when 4: cow=data; break;
    when 5: chicken=data; break;
    etc. forever
     
    • Like Like x 1
  6. Dan Soze

    Dan Soze Member

    Joined:
    Dec 21, 2017
    Messages:
    38
    Likes:
    18
    To fan174,
    Your question seems like a course work assignment.

    Could you be a bit more descriptive what you mean by time?

    For example:
    Is it the current time of day?
    Is it the time since I had lunch?
    Is it the time since the last zero crossing?​
     
    • Like Like x 1
  7. fan174

    fan174 New Member

    Joined:
    Mar 13, 2018
    Messages:
    7
    Likes:
    0
    I want to determine and store time at every zero crossing for 5V AC input signal with PIC16f877a

    T1 2
    T2 2.5
    T3 2.1
    T4 1.9
    .
    .
    Tn Tn

    I am also confuse with interrupt which interrupt should i use external or interrupt on change
     
  8. dave miyares

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    2
    Likes:
    -10


     
  9. Pommie

    Pommie Well-Known Member Most Helpful Member

    Joined:
    Mar 18, 2005
    Messages:
    10,568
    Likes:
    395
    Location:
    Brisbane Australia
    ONLINE
    You keep saying you want to store time - this is meaningless - In my time zone the last crossing was at approximately 18:29:45.24 - is this what you want to store?

    Where are you going to store these times?
    How many times do you need to store?
    What is your level of experience with code?
    What language will this use?

    I hope you're better at coding than asking questions.

    Mike.
     
    • Like Like x 1
  10. fan174

    fan174 New Member

    Joined:
    Mar 13, 2018
    Messages:
    7
    Likes:
    0
  11. Pommie

    Pommie Well-Known Member Most Helpful Member

    Joined:
    Mar 18, 2005
    Messages:
    10,568
    Likes:
    395
    Location:
    Brisbane Australia
    ONLINE
    You need to answer the (4) questions rather than just repeat the same meaningless statement.

    Mike.
     
  12. fan174

    fan174 New Member

    Joined:
    Mar 13, 2018
    Messages:
    7
    Likes:
    0
    I want to store value in variable like
    I want to count continousely
    I have basic knowledge of c Programming
    I know the c programming
     
  13. Pommie

    Pommie Well-Known Member Most Helpful Member

    Joined:
    Mar 18, 2005
    Messages:
    10,568
    Likes:
    395
    Location:
    Brisbane Australia
    ONLINE
    You will need a pic with terrabytes of memory and they don't exist.

    Mike.
     
  14. fan174

    fan174 New Member

    Joined:
    Mar 13, 2018
    Messages:
    7
    Likes:
    0
    It would be possible to just measure first time interval then display on screen for 2 second and
    then again measure second time interval then display on screen for 2 second just repeat the process continousely
     
  15. Pommie

    Pommie Well-Known Member Most Helpful Member

    Joined:
    Mar 18, 2005
    Messages:
    10,568
    Likes:
    395
    Location:
    Brisbane Australia
    ONLINE
    You've finally given some information that means something.
    Two seconds equals 100/120 periods. If you store them in microseconds then 16 bits per variable will work.
    That means you need 200 or 240 bytes of ram.
    You will probably need twice that so you can double buffer the data.

    Mike.
     
  16. fan174

    fan174 New Member

    Joined:
    Mar 13, 2018
    Messages:
    7
    Likes:
    0
    I found in my search that I can use capture mode i to capture the value of Timer 1 when a signal at the CCP pin goes high or low depending on how the CCP is set up. The CCP can accurately capture the arrival time of a signal at the CCP pin. Can I use CCP module to measure time at input signal ?
     

Share This Page