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

How to start PIC16F676 ...??

Discussion in 'Microcontrollers' started by koolguy, Feb 17, 2012.

  1. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,305
    Likes:
    914
    Location:
    Rochdale UK
    ONLINE
    You choose the conversion clock..... If you are reading the adc very fast you need a low divisor (but there are limits... check the datasheet)

    If you sample a much slower changing voltage the largest possible conversion can be used (check the datasheet)

    I think for 4mhz there are only two speeds available...
     
    • Like Like x 1
  2. koolguy

    koolguy Active Member

    Joined:
    Aug 24, 2010
    Messages:
    2,196
    Likes:
    9
    Hi again,
    what is the use of interpt in this program??

     
  3. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,305
    Likes:
    914
    Location:
    Rochdale UK
    ONLINE
    To change the condition of the PWM pin output.

    The timer0 runs and fires an interrupt... the two varibles OnPulse and OfPulse reload the timer0 so the PWM is kept at the right frequency.

    bsf INTCON,T0IE ; Turns on the interrupt for the timer0 overflow..
    bsf INTCON,GIE ; Turns on the global interrupt logic...
     
    • Like Like x 1
  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. koolguy

    koolguy Active Member

    Joined:
    Aug 24, 2010
    Messages:
    2,196
    Likes:
    9

    OK, in this part
    why we are subtracting the W??

    please tell the working of program it will be easier for me to learn it??
     
  6. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,305
    Likes:
    914
    Location:
    Rochdale UK
    ONLINE
    Ok.. this does need a bit of explaining

    the command "sublw .255" subtracts the W reg from decimal 255.

    Because we need the duration of the low part of the PWM signal.

    Think of it this way... if we pre load the timer with 128 and just toggle the pin we would get a nice square wave at 2khz...right!!

    If you want to vary the pulse... but not the frequency.. you can increase the on time to say 145.. but to keep the frequency.. the rest of the time has to equal 255

    so 255 - 145 = 110... the off time needs to equal 110 to keep the frequency at 2khz

    Even if the on time was 1... the off time would need to be 254 to maintain the signal..


    I have been looking over the ASM code... I thought it was WELL commented.

    Re-visit the C code... It's written to do the same thing. It may help.


    Does this answer your question.
     
    Last edited: Apr 3, 2012
    • Like Like x 1
  7. koolguy

    koolguy Active Member

    Joined:
    Aug 24, 2010
    Messages:
    2,196
    Likes:
    9
    Yes, i have trying to learn this code....
     
  8. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,305
    Likes:
    914
    Location:
    Rochdale UK
    ONLINE
    I drew this .... Maybe it helps
     
    • Like Like x 2
  9. koolguy

    koolguy Active Member

    Joined:
    Aug 24, 2010
    Messages:
    2,196
    Likes:
    9
    Hi again,

    In this ADCON0 — A/D CONTROL REGISTER what is the mean of this:-
    1. ADFM: A/D Result Formed Select bit
    1 = Right justified
    0 = Left justified


    2.VCFG: Voltage Reference bit
    1 = VREF pin
    0 = VDD
    how to use Vref pin from where and how??

    3. GO/DONE: A/D Conversion STATUS bit
    1 = A/D conversion cycle in progress. Setting this bit starts an A/D conversion cycle.
    This bit is automatically cleared by hardware when the A/D conversion has completed.
    0 = A/D conversion completed/not in progress
    plaese explain bit more!

    4. ADON: A/D Conversion STATUS bit
    1 = A/D converter module is operating
    0 = A/D converter is shut-off and consumes no operating current
    please explain as we are using zero so, it should be 0 = A/D converter is shut-off and consumes no operating current that mean ADC is shut down so, how can we use it?
     
  10. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,305
    Likes:
    914
    Location:
    Rochdale UK
    ONLINE
    You only turn the ADCON.ADON when you need it.. I set it in the ADC read function.

    10 bits in two bytes ADFM sets either 8 in low and 2 bits high

    OR 2 bits low and 8 bits high.... So you can easily read an 8 bit value...... this is how I've done it.

    Go/DONE strats the conversion... It is also the complete flag you must wait until it goes low until you read the ADC

    VCFG vdd is 5 volts (internally)
     
    Last edited: Apr 4, 2012
    • Like Like x 1
  11. koolguy

    koolguy Active Member

    Joined:
    Aug 24, 2010
    Messages:
    2,196
    Likes:
    9
    HI again,

    I have read about counter in Data sheet(option register), but i want to know how to set the counter increment with reading switch which instruction too use with it.
    I think BTFSS/C will be used but how to set it with counter please tell.
     
  12. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,305
    Likes:
    914
    Location:
    Rochdale UK
    ONLINE
    If you use the timer0 as a counter, you can put the switch on the T0CK pin on RA4. (you'll need a de-bounce circuit )

    If you want to increment a register .

    you will need to de-bounce whatever you do (otherwise you will get erogenous readings).

    when the switch is switched on you need a loop (at least 20mS ) to make sure the switch has done bouncing.

    And when the switch is switched off.

    You can use a Schmitt trigger decoupled with a small cap instead.

    Mosaic has just posted this http://www.electro-tech-online.com/...ith-4-dig-com-anode-7-segment-display.126562/
    It may help.
     
    Last edited: Apr 8, 2012
    • Like Like x 1
  13. be80be

    be80be Well-Known Member

    Joined:
    Aug 23, 2008
    Messages:
    4,869
    Likes:
    144
    Location:
    morristown,tn
    Timer not very good at counting button presses there more for digital signals

    It would be easier to debounce the switch and count it in that loop
     
    • Like Like x 1
  14. colin55

    colin55 Well-Known Member

    Joined:
    Feb 14, 2009
    Messages:
    3,534
    Likes:
    82
    Location:
    Melbourne Australia
    This is the most important decision:
    Do you want to detect the switch and set a flag or send the program to a loop when a switch is detected.
     
    • Like Like x 1
  15. koolguy

    koolguy Active Member

    Joined:
    Aug 24, 2010
    Messages:
    2,196
    Likes:
    9
    Hi,
    Actually i want to learn Timer for various purpose!
     
  16. Mosaic

    Mosaic Well-Known Member

    Joined:
    Jun 3, 2010
    Messages:
    2,612
    Likes:
    129
    Location:
    Caribbean
    RITESH:

    Perhaps you should consider Nigel's tutorials or any of the other PIC tuts which are widely available. You can't learn well if u go about it piecemeal like this. You need fundamentals and you build on them. Datasheets are also important as is the microchip site for selecting the correct chip capabilities for your project. When u say u want to learn about the Timer, do u know that there are several Timers in the larger PICs, each with special capabilities?
     
    • Like Like x 1
  17. colin55

    colin55 Well-Known Member

    Joined:
    Feb 14, 2009
    Messages:
    3,534
    Likes:
    82
    Location:
    Melbourne Australia
    Keep to the topic.
     
    • Like Like x 1
  18. koolguy

    koolguy Active Member

    Joined:
    Aug 24, 2010
    Messages:
    2,196
    Likes:
    9

    yes........!
     
  19. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,305
    Likes:
    914
    Location:
    Rochdale UK
    ONLINE
    Ritesh.... Here is a good place to learn all the base line functions on a pic..http://www.electro-tech-online.com/custompdfs/2012/04/PIC_Base_A_5.pdf.

    There is many tutorials but the one posted is for the timer0.


    Everyone esle!!! Remember that Ritesh seems to use the smallest of pics pic16f676... Small memory. Small ram..... You know... Small!!

    It's a decent enough chip but the functions are limited...
     
    • Like Like x 1
  20. koolguy

    koolguy Active Member

    Joined:
    Aug 24, 2010
    Messages:
    2,196
    Likes:
    9
    Hi again,
    While using counter from option register setting by TMR0...where that counter value is stored??
     
  21. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,305
    Likes:
    914
    Location:
    Rochdale UK
    ONLINE
    TMR0 is the counter register... The OPTION_REG only has the pre-scaler bits. If you access the TMR0 reg at any time you will retrieve the contents of the timer...
     
    • Like Like x 1

Share This Page