Continue to Site

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.

  • 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.

How to start PIC16F676 ...??

Status
Not open for further replies.
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...
 
Hi again,
what is the use of interpt in this program??

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...
 
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:
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?
 
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:
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.
 
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 https://www.electro-tech-online.com...ith-4-dig-com-anode-7-segment-display.126562/
It may help.
 
Last edited:
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
 
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.
 
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?
 
Ritesh.... Here is a good place to learn all the base line functions on a pic..https://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...
 
Hi again,
While using counter from option register setting by TMR0...where that counter value is stored??
 
Status
Not open for further replies.

Latest threads

Back
Top