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.

Digital Signal Capture

Status
Not open for further replies.

Incaviglia

New Member
I'm attempting to capture a digital signal (on off) with a pic18f46k20. I'm thinking that I will reconstruct the signal by using a timer to measure how long the signal is in a given state; I'll document the value of the timer each time the signal changes states.

I have an electronics background but I have very limited experience with microcontroller code. I don't even know where to begin with this. Is this even a good way to do this? Can I use the CCP module (how do you use that, anyway?)?

Please help.
 
Set up a timer so it counts the cpu clock (divided down if necessary). One of the port pins will cause an interupt on change. On every interupt, copy the timer value into a ram location. If you want a delta time, then subtract the timer value on the previous edge from the present time. You can set it up to capture times between up-edges, down-edges, or each change regardless of direction, which would be more complicated. In the latter case, you might have to separate up-dn deltas from dn-up deltas by putting them in two lists. Since the timer value might have moduloed between two sucessive reads of the timer value, you might have to adjust for that.

Since there is not much ram, you might have to transmit the deltas off the chip using a comm channel rather than storing a long list.
 
Last edited:
The signal is not periodic, so wouldn't you need to set it up to detect changes regardless of direction? Is it possible to set it up to detect changes on up edges and down edges? What do you mean about the timer being moduloed? Can you explain, please?

Thank you very much.
 
Could you setup two comparator channels, one to detect rising edge and one for falling edge? Then grab the timer values at those interrupts? Or is that what you are saying Mike?
 
smanches, I think I'm on the same page as you.

I'm thinking the way to do this is:
-have a timer run
-use CCP1 module to detect rising edges
-use CCP2 module to detect falling edges
-store data to an array, perform math operations to reconstruct signal, etc

That is possible, right? It seems pretty logical to me, but is there a better way to go about this?

My only concern (and it's just an afterthought) is that this pic only has 2 CCP modules and I might want to capture 2 signals simultaneously - would this be possible?
 
The PIC has "generate interrupt on port pin change" hardware. It can be armed three ways: only up; only down; or either up or down. You do not have to write an Interrupt Service Routine to take advantage of this; just poll the bit that gets set when the condition occurs in your mail software loop.

If the wave is non periodic, it is up to you to figure out what is the significance of the high period vs the low period vs the period between up edges vs the period between down edges. What is significant depends on what is producing the wave.

What are the periods we are talking about? That will determine if you have time to transmit the digits representing those periods off the PIC in real time, or if you have to buffer them on the PIC?

Counter/Timers count 0 to 255 or 0 to 65535. When the counter rolls over, and begins counting again from zero, that is called "modulo". If you are subtracting the previous value of a timer from the present value, and if you get a negative result, the timer moduloed between the two reads. To adjust for the counter rollover, you add either 256 or 65536 to the negative value to fix it...
 
Last edited:
Thanks, Mike. We're talking about DTMF tones put through a circuit that turns them to a PWN signal. Where is the "generate interrupt on port pin change" hardware? That's the first I've heard of that, but it sounds like just what I'm looking for. Is there some place it's referenced in the data sheet?
 
Paragraph 10.3.2 INTERRUPT-ON-CHANGE of the datasheet

If your goal is to decode DTMF inside the pic, follow the links in this thread.
 
My goal is to capture any digital signal, the DTMF PWM signal will just be used in testing. It will serve as the maximum frequency that I'll need to be able to handle.

So I should be able to run a timer and note every change using this interrupt-on-change pin to note the time and store that value in an array? I'm not familiar with the interrupt-on-change, and the datasheet doesn't have much on it. Am I missing something in there? How do I set it up?
 
Status
Not open for further replies.

Latest threads

Back
Top