Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

pic 18f4550 read frequency?

Status
Not open for further replies.

coolgod

Junior Member level 2
Joined
Apr 2, 2011
Messages
21
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,463
Hello everyone.
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
 

you could use a timer to generate interrupts (say at 20KHz) incrementing 4 counters.
you could then poll or use PORTB input change interrupt looking for a change of state of the sensors.
When a change occurs the corresponding counter would give you the number of timer interrupts since the previous change hence the period
 

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.
 

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?
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top