|
|
View previous topic :: View next topic |
Author |
Message |
kamputty Guest
|
Okay, please forgive this question! External int question... |
Posted: Fri Feb 02, 2007 5:43 pm |
|
|
Hi all,
Okay, simple question, but not for me!
I want to create an external int, so I'll use this
Code: |
#int_ext
void external_isr_1()
{
// do something fast!
}
|
Now, pin B0 is connected to this. All I want to do is hookup a osc to this. To be honest, I'm not sure what to do.
How should I hook this up? There are only 2 pins! One must go to ground, and the other to B0? Or do I need to add some other parts?!
BLA!
~Kam (^8* |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Feb 02, 2007 5:52 pm |
|
|
Quote: | All I want to do is hookup a osc to this |
For what purpose ? It takes time to service an interrupt. If you're
running at 4 MHz, it might take 40 or 50 usec to get in and out of the
interrupt. What frequency oscillator do you intend to connect to this
pin, and why ? |
|
|
rnielsen
Joined: 23 Sep 2003 Posts: 852 Location: Utah
|
|
Posted: Fri Feb 02, 2007 5:55 pm |
|
|
You want to hook up a crystal to this input and cause an interrupt at the frequency of the crystal???? Or, do you want to use B0 as an output? If you are using a crystal the circuitry to drive it is not there. The crystal will not oscillate. Describe, in greater detail, just what it is you are trying to accomplish.
Ronald |
|
|
kender
Joined: 09 Aug 2004 Posts: 768 Location: Silicon Valley
|
|
|
kamputty Guest
|
I'm on crack! |
Posted: Fri Feb 02, 2007 8:14 pm |
|
|
Hi all,
Let me start by saying that I must be on crack, else it's Friday.
What I mean to say is this
I need to connect an osc to my TIMER0, not the ext int!
So my code is as such
Code: |
#int_TIMER0
void TIMER0_isr()
{
counter++;
}
|
I want to hook up a 14.31818Mhz osc to timer0, giving me 3.579545Mhz heart beat (osc/4).
Said that, I need to connect one end to the PIC (I believe its RA4/TOCKI) and the other end to ???? (must be either - or +!)
What I ultimately want is a 3.579545 heartbeat...
Well, there it is.
~Kam (^8* |
|
|
Ttelmah Guest
|
|
Posted: Sat Feb 03, 2007 4:02 am |
|
|
First thing to get clear, is do you have an external oscillator, or just a crystal?. This was raised before, but still applies.
If the former, then Timer1, can be setup with:
setup_timer1(T1_EXTERNAL | T1_DIV_BY_4);
If the latter, then T1_CLK_OUT, also needs to be 'ored' into the setup.
For the former, only one connection to the timer1 input is needed, for the latter, the crystal needs to go between the timer1 input, and output pins with suitable capacitors.
Now, at this point, 'Timer1', will be clocking off the external frequency over 4, and the contents of the timer1 counter registers can be read at any time to give a 'heartbeat' tick value. The interrupt will occur every 65536 ticks (54.6 times/second).
To get an actual long 'counter' at 3.57MHz, you need to treat the 'counter' value being incremented in the timer, as the 'overflow' from the hardware timer, to give a 24bit, or 32bit counter.
Best Wishes |
|
|
kam
Joined: 15 Jul 2005 Posts: 59
|
|
Posted: Sat Feb 03, 2007 11:49 am |
|
|
Okay, as you've seen, I know nothing about electronics! I need to stick with making bagels or something...I'm sure I can squish bready blobs and make bagels things better then I can connect 2 wires together (okay, I am getting better at soldering! )
I want to do this...
I'm currently working on a pic@20mhz ntsc character generator. I have successfully "drawn" lines on the tv etc. via a RCA cable. Yippeeee!
Now, I would like to get a 3.579545Mhz heart beat to manage the color burst freq.
I would like to drive Timer0 with that beat, so I can sync the tv updating.
I have a full can 14.31818Mhz oscillator with 4 pins
http://www.jameco.com/webapp/wcs/stores/servlet/ProductDisplay?langId=-1&storeId=10001&catalogId=10001&productId=108652
As mentioned, I can then issue
Code: |
setup_timer1(T1_EXTERNAL | T1_DIV_BY_4);
|
Okay, here goes my question, and please be kind! ( )
How do I physically hook up the 4 pin osc to timer0?! There are 4 pins, and on the site, I cannot find any datasheets...
I've come to doubt everything I do with the physical electronics...
Well, there it is!
~Kam (^8* |
|
|
kam
Joined: 15 Jul 2005 Posts: 59
|
|
Posted: Sat Feb 03, 2007 4:11 pm |
|
|
okay, I think this is it!
pin 1:
pin 7: Ground
pin 8: Output
pin 14: Vcc
Gonna give it a try! hopefully no smoke released...
~Kam (^8* |
|
|
Ttelmah Guest
|
|
Posted: Sun Feb 04, 2007 3:52 am |
|
|
I think, reading some of your latter posts, what you are after, is not a 'heartbeat', but a _clock_.
A heartbeat', in computer terms, is something where events are triggered at a regular interval. Hence on the PC, there is a 'heartbeat' interrupt at 18mSec, or 10mSec, depending on the OS involved. You appear to want to develop the colourburst 'clock', from an external clock at 4* the frequency. If so, this _cannot_ be done with timer1. The code given, is to trigger an internal counter, at the colourburst clock frequency. No output will be produced.
It is not possible on most PICs, to do what you want. The only systems, that supports producing an external clock at high frequency, are the CPU master clock itself (which can produce IP/4), or the CCP, which on most chips, is tied to Timer2, which does not support using an external clock.
As such, the only way I can think of to do this, would be to get rid of the 20MHz clock, and the 14Mhz one, and run the processor master clock off twice the colourburst frequency. Then if the chip involved is one with the *4 PLL, the CPU could be run at 28.6MHz, and the PWM, could be used to produce the required frequency
Best Wishes |
|
|
kam
Joined: 15 Jul 2005 Posts: 59
|
|
Posted: Sun Feb 04, 2007 9:56 am |
|
|
Morning all,
Okay, some more questions...
#1. If I have an osc on timer0 at 14.31818Mhz then using osc/4, this gives me a beat of 3.579545Mhz. Is this not possible? I'm still not sure what I am missing if this is not true.
#2. Once I get the "beat" in my isr, I can update the signal as I need to. The line
Code: |
#int_TIMER0
void TIMER0_isr()
{
counter++;
}
|
is just an illustration on the isr, not the logic. The "counter++" is just junk code, nothing more.
The purpose of the isr is to produce a single voltage (0~1v) for a single element within the scanline timeline, actually for all the lines from a buffer.
I have another isr that does nothing more then update the buffer, but that is not timing critical.
Am I waaaaaaaaaaaaay off base here in regards of timer0?!
Thanks for the replies! Great learning experience....
~Kam (^8* |
|
|
SherpaDoug
Joined: 07 Sep 2003 Posts: 1640 Location: Cape Cod Mass USA
|
|
Posted: Sun Feb 04, 2007 11:15 am |
|
|
Trying to generate a color burst on a PIC is going to be VERY difficult. If you have an internal clock of 3.579MHz it doesn't mean you can toggle a pin in software at that rate. If you poll the timer till it ticks and then set the pin to 1, then you wait till the timer ticks again to set the pin to 0 you will only get half the 3.579MHz rate.
You could poll for a tick, set the pin to 1, wait some short delay, set the pin to 0, and poll for the next tick. But that would give an asymmetrical output.
With some PICs you might get a 2x3.579MHZ internal clock so you could poll for 1 and poll for 0, but the PIC isn't going to have time to do ANYTHING else.
Trying to use interrupts at these rates is hopeless.
This is going to be really hard, probably impossible. If you want to learn about generating complex signals try working with audio. I once built a 25 to 32kHz synthesizer for sonar work and it took every clock cycle my PIC16C58 could muster.
If you have to generate color video signals start looking at dedicated chips for video work. _________________ The search for better is endless. Instead simply find very good and get the job done. |
|
|
kam
Joined: 15 Jul 2005 Posts: 59
|
|
Posted: Sun Feb 04, 2007 12:52 pm |
|
|
Hmmm....well, thats not good!
I've gotten black and white working just fine. Granted not as an interrupt, but the same logic. I only change the state from old to new within specific time. I have 2 "processes", one (the interrupt) that just sends one bit (actually 2, but they are combined) of information to the tv from a buffer. This could be sync, white, black, grey in the b/w version. So all I am doing is changing state from x to y, and it will keep that state until the next change. The process is fast because all it does is push a specific bit out from a buffer. No logic, just send bit, send bit, send bit etc.
The second process manages the buffer, stalling as need be etc.
All I'm using the timer for is to maintain sync with the tv, actually, have the tv sync with me!
I still gonna try. I feel it can be done (famous last words! )
~Kam (^8* |
|
|
Ttelmah Guest
|
|
Posted: Sun Feb 04, 2007 3:45 pm |
|
|
kam wrote: | Morning all,
Okay, some more questions...
#1. If I have an osc on timer0 at 14.31818Mhz then using osc/4, this gives me a beat of 3.579545Mhz. Is this not possible? I'm still not sure what I am missing if this is not true.
#2. Once I get the "beat" in my isr, I can update the signal as I need to. The line
Code: |
#int_TIMER0
void TIMER0_isr()
{
counter++;
}
|
is just an illustration on the isr, not the logic. The "counter++" is just junk code, nothing more.
The purpose of the isr is to produce a single voltage (0~1v) for a single element within the scanline timeline, actually for all the lines from a buffer.
I have another isr that does nothing more then update the buffer, but that is not timing critical.
Am I waaaaaaaaaaaaay off base here in regards of timer0?!
Thanks for the replies! Great learning experience....
~Kam (^8* |
The chip develops 'OSC/4' internally. It is _not_ available to you outside the chip. The interrupt gets triggered when the counter overflows, which is 65536 cycles of this clock....
Best Wishes |
|
|
kam
Joined: 15 Jul 2005 Posts: 59
|
|
Posted: Sun Feb 04, 2007 4:31 pm |
|
|
Ttelmah wrote: |
The chip develops 'OSC/4' internally. It is _not_ available to you outside the chip. The interrupt gets triggered when the counter overflows, which is 65536 cycles of this clock.... |
Just to make sure I understand, I was assuming that using a 14.x Mhz osc will be dived by 4 (osc/4) automagically by the PIC giving me an effective 3.x clock. If I set the interrupt "count" to 0xffff with the interrupt, then I'm assuming that I can get the 3.x interrupts I need.
If this is not true, please please please explain ( ) because my root understanding is wrong.
Forget about color sync, etc., all I want to do is connect an external oscillator to a timer, and get that many "hits" per second.
Again, thanks to all...very enlightening.
~Kam (^8* |
|
|
newguy
Joined: 24 Jun 2004 Posts: 1911
|
|
Posted: Sun Feb 04, 2007 4:59 pm |
|
|
If the processor didn't have to do anything else, then yes, what you are proposing would work. However, what you're overlooking is the overhead involved in the interrupt. When the PIC gets an interrupt, it has to stop what it's doing, set aside whatever it was working on, then get to the interrupt, and finally get back to whatever it was doing when the interrupt was received in the first place.
All this takes clock cycles. With CCS, you're looking at 40 - 80 clock cycles total (give or take a few). So, your clock is ticking along at approximately 0.28 us (= 4/14,320,000 Hz), so the quickest you could hope to service an interrupt would be approximately every 11 to 22 us. This equates to a frequency of about 45 kHz - 90 kHz TOPS.
You could a very small improvement in speed by simply checking the timer's interrupt flag, but I doubt that the improvement would be much better than a factor of 3 - 4 at best. |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|