Getting TTL square wave or pulse train input

Post
coolgod
New Member
2011/03/28 13:08:21
Hi I have a pic 18f4550 chip and I would like to get direct input for a light sensitivty to frequency converter.
http://www.sparkfun.com/datasheets/Sensors/TSL230R-LF-e3.pdf
I read somewhere there is an internal module inside the PIC that can calulate the frequency by using a (ttl input) and a internal automatic counter????
Can anyone explain the ttl input? what does that mean>
Can anyone also tell us which module we should use inside the pic?
Is it the CCP module?
Ty very much
post edited by coolgod - 2011/03/28 13:09:59
WaltR
Super Member
Re:Getting TTL square wave or pulse train input 2011/03/28 13:29:06
TTL = Transistor-Transistor-logic
From Google is Wiki:
http://en.wikipedia.org/w...%80%93transistor_logic

Today its used generically for any 5V logic.

The CCP module can be use as can polling an input or triggering an interrupt.
You will need to write the code that calculates the frequency from these methods that measure the input period.
coolgod
New Member
Re:Getting TTL square wave or pulse train input 2011/03/28 13:34:51
polling is counting the number of rises/ falls in a certain interval?
So is there a specific module used for this, excluding ccp because we've used up 2 of our ccp pins.
If so, it it related to timer counter mode, or is there a better way?
the official documentation gives some explanation
"The frequency-scaling function allows the output range to be optimized for a variety of measurement
techniques. The divide-by-1 or straight-through output can be used with a frequency counter, pulse
accumulator, or high-speed timer (period measurement). The divided-down outputs may be used where only
a slower frequency counter is available, such as a low-cost microcontroller, or where period measurement
techniques are used. The divide-by-10 and divide-by-100 outputs provide lower frequency ranges for high
resolution-period measurement."
which one of those 3 techniques are applicable to our chip.
post edited by coolgod - 2011/03/28 14:21:17
WaltR
Super Member
Re:Getting TTL square wave or pulse train input 2011/03/28 14:56:09
What is the frequency range you expect?

Do the math for the various methods and chose the best one that meets your requirements.
coolgod
New Member
Re:Getting TTL square wave or pulse train input 2011/03/28 15:25:56
the output frequency can be scaled down if needed.
Raw output/frequency unscaled can reach 120 khz.
Is timer counter mode the only option available?
Or can i take any pin and just count the number of high peak(1) happening in a certain time frequency to determine the recieved frequency.
DarioG
Scheisse Menschen
Re:Getting TTL square wave or pulse train input 2011/03/28 16:01:29
Yeah you can do both - I'm building a RpM engine counter now
coolgod
New Member
Re:Getting TTL square wave or pulse train input 2011/04/02 12:24:35
I'm a high school student working on a photovore robot.
It basically follows light.
I've gotten 4 light to frequency converters and would like to be able to get the data from all 4 sensors.
I don't exactly know how to implement this.
I know the output from the sensors can be 120-600nm pulse duration pulse train with a frequency of 0.8~1.2 khz or 0.4~0.6 khz 50% duty cycle square wave output.
I think the timer0 has counter mode that automatically increments on rising or falling edge of the input. According to the datasheet the other timers have a counter mode but not this functions?
Anyone can tell me another way of getting data from my sensors? Ty
DarioG
Scheisse Menschen
Re:Getting TTL square wave or pulse train input 2011/04/03 02:43:35
I used Timer 2 to count external pulses and Timer 1 to read, store and reset Timer 2 every 100mSec: I get values from 2 to 200 when input frequency ranges from 20 to 2000Hz, pretty good for a car engine. I don't need much precision since I'm only setting 15 leds in 500rpm steps.

(on a 18F4620 in C)
atferrari
Super Member
Re:Getting TTL square wave or pulse train input 2011/04/03 08:12:06
DarioG

I used Timer 2 to count external pulses and Timer 1 to read, store and reset Timer 2 every 100mSec: I get values from 2 to 200 when input frequency ranges from 20 to 2000Hz, pretty good for a car engine. I don't need much precision since I'm only setting 15 leds in 500rpm steps.

(on a 18F4620 in C)


Briefly DarĂ­o, what the user would see?

2000 - 20 = 1980

1980 / 500 = 4 LEDs

or

15 * 500 = 7500

(?)
DarioG
Scheisse Menschen
Re:Getting TTL square wave or pulse train input 2011/04/03 15:30:48
Yep, 1980 would make 3 led (2000 => 4); I have 14 leds at this time, ranging up to 7000 RpM (theorically); I am wondering about adding another led, steady, as "500" and push upper limit to 7500 - which is anyway useless since the standard engine won't go above 6000.
atferrari
Super Member
Re:Getting TTL square wave or pulse train input 2011/04/04 03:46:49
OK. It is clear now.
coolgod
New Member
Re:Getting TTL square wave or pulse train input 2011/04/04 21:52:08
Ok thank you for all your help.
I've gotten my inputs done.
Ty very much.
I'm going to ask a noob questions.
The __CONFIG() statement
how exactly does it work
take this sample code from hi-tech c examples
__CONFIG(2, BOREN & BORV45 & PWRTEN & WDTPS128 & WDTDIS);
It's suppose to modify the 2nd configuration bits register(word) right?
How does it do that? aren't BOREN,BORV45,PWRTEN all predefined bit names inside that register? How does ANDing them together do anything?
I'm also a little confused on interrupts also? Do i just need to set interrupts up and make a function called void XXXXX ISR()
and thats is the interrupt? Easy as that? No memory complicated stuff?
Ty again for answering my noob questions.

WaltR
Super Member
Re:Getting TTL square wave or pulse train input 2011/04/05 07:04:37
Look in your compiler manual, in the MPLAB Help and in the header file for info on the CONFIG statement. Work through AND'ing the binary values of the names from the header file and you'll see how this works.

That is just about it for an ISR in C. Check the Compiler manual for more.

In case you haven't seen this tutorial:
http://www.gooligum.com.au/tutorials.html
Does cover your questions.
coolgod
New Member
Re:Getting TTL square wave or pulse train input 2011/04/06 22:30:34
I've gotten the interrupts to work and figured out how the config works.
Ty guys very much.
Looking back I'm really greatful for all the help you guys have given.

#include <htc.h>
#include <pic18f4550.h>
volatile unsigned int ls;
volatile unsigned int rs;
volatile unsigned int tt;
__CONFIG(1,USBPLL&PLLDIV2&CPUDIV1&INTCLKO);
__CONFIG(2,WDTPS32K&WDTDIS);
interrupt void low_priority lisr (void)
{
if(TMR3IF)
{
rs=TMR1L;
ls=TMR0L;
TMR1L=0x00;
TMR0L=0x00;
tt++;
TMR3IF=0;
}
}

void main()
{
tt=0;
T0CON=0x28;
T1CON=0x86;
T3CON=0xF4;
IPEN=1;
TMR3IP=0;
PIE2=0x02;
PIE1=0x00;
GIE=1;
PEIE=1;
TMR0IE=0;
INT0IE=0;
RBIE=0;
INT2IE=0;
INT1IE=0;
TMR0ON=1;
TMR1ON=1;
TMR3ON=1;

while(1)
{

}
}


I'm using a pickit 2 knockoff programmer and board from a friend. 
I was testing the inputs and found something strange.
I was viewing them throught the "watch" inside view drop down menu.
From my data I pretty much concluded that my PIC wasn't operating at 48mhz. So after doing a little research I was still puzzled. Can the PIC run at 48mhz during debug mode?
I messed around with config bits and some registers with no luck.
i have __CONFIG(1,USBPLL&PLLDIV2&INTCLKO);
pll prescaler divide by 2,
Internal oscillator, CLKO function on RA6, EC used by USB (INTCKO)
my system clock select bit is 00(primary oscillator)
Any reason why my pic is running slower than it should be?
paulbergsman
Super Member
Re:Getting TTL square wave or pulse train input 2011/04/09 19:05:52
coolgod

Hi I have a pic 18f4550 chip and I would like to get direct input for a light sensitivty to frequency converter.
http://www.sparkfun.com/datasheets/Sensors/TSL230R-LF-e3.pdf
I read somewhere there is an internal module inside the PIC that can calulate the frequency by using a (ttl input) and a internal automatic counter????
Can anyone explain the ttl input? what does that mean>
Can anyone also tell us which module we should use inside the pic?
Is it the CCP module?
Ty very much



Just about any Mid-Range PIC can take a frequency measurement using TOCK1, and TMR0.
Application Note AN592 provides the theory, and source code, for a 50Hz to 50MHz frequency counter.

paulbergsman
Super Member
Re:Getting TTL square wave or pulse train input 2011/04/09 19:15:12
coolgod

Hi I have a pic 18f4550 chip and I would like to get direct input for a light sensitivty to frequency converter.
http://www.sparkfun.com/datasheets/Sensors/TSL230R-LF-e3.pdf
I read somewhere there is an internal module inside the PIC that can calulate the frequency by using a (ttl input) and a internal automatic counter????
Can anyone explain the ttl input? what does that mean>
Can anyone also tell us which module we should use inside the pic?
Is it the CCP module?
Ty very much



Just about any Mid-Range PIC can take a frequency measurement using TOCK1, and TMR0.
Application Note AN592 provides the theory, and source code, for a 50Hz to 50MHz frequency counter.