Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
LinkBack Thread Tools Display Modes
Old 5th October 2004, 10:59 PM   (permalink)
Default

what you are asking , i think , is how do you make decisions with a pic..
you do this by using the BTFSC- Bit Test F Skip if Clear instruction.
and the BTFSS - Bit Test F Skip if Set instruction..
williB is offline  
Old 6th October 2004, 12:13 AM   (permalink)
Default

Nigel Goodwin wrote:
Quote:
You can't read and write with the same instruction, you can either read OR write a single bit (witht the commands you mentioned above), or you can read OR write the complete port.
Without wanting to muddy the waters too much, I think you'll find that BSF and BCF not to mention a bunch of others, are all read-modify-write instructions. There have been many times when I have wished that BSF wasn't, but that's how I know that it is!
JohnBrown is offline  
Old 6th October 2004, 04:49 AM   (permalink)
Default

Quote:
How it can be possible? I still can't imagine!,
does timer0 and timer1 and even timer2 can work simultaneusly without delaying the other process of the microcontroler, as delays do
you use the delay as a subroutine..a block of code that is "Called" when needed.
when an event is presented to RB0/INT you would test the DIP Switch.
then jump to a subroutine depending the position of the switches.
williB is offline  
Old 6th October 2004, 06:44 PM   (permalink)
Default

Ok guys, I got it.

but delays are time consuming, the uC can't do anything else, just the delay, my question is, can I use timer0, timer1, and ADC run at the same time?.

for example if I got a interrupt form RB0, then timer0 runs, when the delay time is running I want to sample an analog signal from AN0. When the timer0 has reached n times the value i need (counterA), then timer0 will run still, with another counter (counterB) I will tried to reach a time, lets say 3 min, if no other even occur, if so this last counter will be cleared. and so on

that's why i want to know if timers, adc can work simultaneusly, delays, stay at the rutine up to the end
sardineta is offline  
Old 6th October 2004, 10:42 PM   (permalink)
Default

Quote:
Originally Posted by sardineta
that's why i want to know if timers, adc can work simultaneusly, delays, stay at the rutine up to the end
There are many things that can appear to run simultaneously (even if many of them actually don't), it's all a question of programming it accordingly.

But there's no magic 'this will work for everything', you have to program each case on it's merits - probably a mixture of polling and interrupts, depending what you are wanting to do.

Try asking about EXACTLY what you want to do!.
__________________
PIC programmer software, and PIC Tutorials at:
http://www.winpicprog.co.uk
Nigel Goodwin is offline  
Old 7th October 2004, 05:36 PM   (permalink)
Default

This is what I want:

initializate interrupt for RB0/INT
so it will be always runing, when and event is occurred a counterA will be incremented

intializate ADC, I can start/stop the ADC when I want

Initializate timer0
it will run forever, and generates an interrupt every 20ms

if by the ADC I detect 1.25V = (ADRESH=0, ADRESL=256)
and if this event occurs for an equal interval of 300ms then I should turn on a led and increment counterB. then after 1 minute I should turn off the led

if againf by the ADC I detect 1.25V, and it persists for 300mS I should turn on a led, after one minute I should stop the led and increment counterB.


but, if before the second event there haven't been any other event for about 30 minutes then I should clear counterB

how i can gent the 30 minutes, without taking processing time as delays do
with timer1, this is a 16 bit register.

also I want to know if ADC can run without taking processing as delays
sardineta is offline  
Old 7th October 2004, 08:11 PM   (permalink)
Default

Quote:
Originally Posted by sardineta
how i can gent the 30 minutes, without taking processing time as delays do
with timer1, this is a 16 bit register.
If you're already using timer0 to generate interrupts every 20mS, use that same clock - simply increment, or decrement, registers in order to get the time you require. For a 20mS interrupt the first obvious counter is from (or to) 50, to give a count in seconds, from that you count again, from (or to) 60, to give minutes - and so on as long as you need!.
__________________
PIC programmer software, and PIC Tutorials at:
http://www.winpicprog.co.uk
Nigel Goodwin is offline  
Old 7th October 2004, 08:54 PM   (permalink)
Default

Ok, That is a good idea, but it cause me pain.

:?
sardineta is offline  
Old 8th October 2004, 05:26 PM   (permalink)
Default ADC Vs RB0

what happens when i am waiting the ADC to finish and before it occurs and interrupt from RB0 occurs, does the ADC still sample the signal or it stops and then will start again the sampling or it will go through the code.
sardineta is offline  
Old 8th October 2004, 05:43 PM   (permalink)
Default Re: ADC Vs RB0

Quote:
Originally Posted by sardineta
what happens when i am waiting the ADC to finish and before it occurs and interrupt from RB0 occurs, does the ADC still sample the signal or it stops and then will start again the sampling or it will go through the code.
The ADC operates seperately from the processor, so it will continue to sample while the interrupt routine is active. When the interrupt routine returns it will find the flag set if the ADC has finished - assuming you're using polling to check for the ADC finishing?.
__________________
PIC programmer software, and PIC Tutorials at:
http://www.winpicprog.co.uk
Nigel Goodwin is offline  
Old 8th October 2004, 06:12 PM   (permalink)
Default

thanks a lot!
what about if I am not polling the ADC, I mean I will enable this periphereal interrupt and If ADC finish while RB0 interrupt was attended or any other interrupt is generated.


what happens?

I will use the followinf interrupts
TIMER0 every 20ms
RB0/INT, external event
ADC
sardineta is offline  
Old 8th October 2004, 09:54 PM   (permalink)
Default

Quote:
Originally Posted by sardineta
thanks a lot!
what about if I am not polling the ADC, I mean I will enable this periphereal interrupt and If ADC finish while RB0 interrupt was attended or any other interrupt is generated.


what happens?

I will use the followinf interrupts
TIMER0 every 20ms
RB0/INT, external event
ADC
You should arrange your program to minimise the number of simultaneous interrupts - when an interrupt is called it disables further interrupts, and your interrupt code should enable then again as it exits, when any pending interrupts will be serviced.

I don't claim to be an expert on PIC interrupts, I only use them occasionally - mostly you can avoid using them - from your description so far it looks like you probably only require the 20mS timer interrupt. Most interrupt intensive code you see consists of sitting in endless loops waiting for an interrupt to occur, you may as well carry out polling during this loop instead.
__________________
PIC programmer software, and PIC Tutorials at:
http://www.winpicprog.co.uk
Nigel Goodwin is offline  
Old 12th October 2004, 03:43 PM   (permalink)
Default ADC

I have heard that the input impedance to the ADC from the microcontroller should be 2.5K.

what about if I directly connect a potentiometer to handle a voltage level to the ADC input.

what about the input impedance?

this effect is saw when using opamps? or when I should take care of it?

c u
sardineta is offline  
Old 12th October 2004, 03:55 PM   (permalink)
Default Re: ADC

Quote:
Originally Posted by sardineta
I have heard that the input impedance to the ADC from the microcontroller should be 2.5K.

what about if I directly connect a potentiometer to handle a voltage level to the ADC input.
The main problem is the speed of charging the internal sample and hold capacitor, you may have to wait a substanial time between samples, particularly when switching channels. Although it's been suggested that accuracy can suffer slightly as well - but I've not checked this, from the suggestion accuracy should still be plenty higher than your support components (so I don't see it as a problem!).

Quote:
what about the input impedance?

this effect is saw when using opamps? or when I should take care of it?
If you feed the A2D input from an opamp you won't see the effect, you should do this is you want maximum speed!.
__________________
PIC programmer software, and PIC Tutorials at:
http://www.winpicprog.co.uk
Nigel Goodwin is offline  
Old 15th October 2004, 04:32 PM   (permalink)
Default

I have 2Kx14 of flash memory (program memory) in the 16F870 uC

I have already compiled my asm code and this process generated a hex file of 2657 bytes.

Does this file fit in the PROGRAM MEMORY?

Another question:
Every variable I need, it should be initializad to zero by software?.

--------------------------
example equ 0x20
....

movlw 0x00
movwf example
--------------------------

or on power on data memory all bytes are zero.
I would like to know it because if ram is initialized to 0's on power on my code redeuce because I do not do it by software, but it still is above 2400 bytes.


Thanks in advanced
sardineta is offline  
Reply

Bookmarks

Thread Tools
Display Modes





All times are GMT. The time now is 07:49 AM.


Electronic Circuits  |  Learning Electronics
Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.

eXTReMe Tracker