Thread: PIC 18F2431
View Single Post
  #7   Spotlight this post!  
Unread 22-08-2005, 13:51
Sparks333's Avatar
Sparks333 Sparks333 is offline
Robotics Engineer
AKA: Dane B.
FRC #1425 (Wilsonville Robotics)
Team Role: Alumni
 
Join Date: Feb 2004
Rookie Year: 2003
Location: Wilsonville, Oregon
Posts: 184
Sparks333 is a glorious beacon of lightSparks333 is a glorious beacon of lightSparks333 is a glorious beacon of lightSparks333 is a glorious beacon of lightSparks333 is a glorious beacon of lightSparks333 is a glorious beacon of light
Send a message via AIM to Sparks333
Re: PIC 18F2431

Okay,
Sorry it took so long, but I was on vacation.

Here's the code. Keep in mind that I am a beginner, with rudimentary understanding of C, and even less experience with PICs.


#include <stdio.h>
#include <p18f2431.h>

void main (void)
{

CAP1BUFL = 0x00;
INTCONbits.GIE = 0;
INTCONbits.PEIE = 0;
IPR3bits.IC1IP = 0;
IPR3bits.IC2QEIP = 0;
IPR3bits.IC3DRIP = 0;
PIE3bits.IC1IE = 0;
PIE3bits.IC2QEIE = 0;
PIE3bits.IC3DRIE = 0;
PIR3bits.IC1IF = 0;
PIR3bits.IC2QEIF = 0;
PIR3bits.IC3DRIF = 0;
T5CONbits.TMR5ON = 1;
T5CONbits.TMR5CS = 0;
T5CONbits.T5PS1 = 0;
T5CONbits.T5PS0 = 0;
T5CONbits.T5MOD = 0;
T5CONbits.RESEN = 0;
T5CONbits.T5SEN = 1;
CAP1CON = 0x00;
CAP1CONbits.CAP1REN = 1;
CAP1CONbits.CAP1M3 = 0;
CAP1CONbits.CAP1M2 = 1;
CAP1CONbits.CAP1M1 = 1;
CAP1CONbits.CAP1M0 = 1;
DFLTCONbits.FLTCK0 = 0;
DFLTCONbits.FLTCK1 = 0;
DFLTCONbits.FLTCK2 = 0;
DFLTCONbits.FLT1EN = 1;
DFLTCONbits.FLT2EN = 0;
DFLTCONbits.FLT3EN = 0;
DFLTCONbits.FLT4EN = 0;
QEICONbits.PDEC0 = 0;
QEICONbits.PDEC1 = 0;
QEICONbits.QEIM0 = 0;
QEICONbits.QEIM1 = 0;
QEICONbits.QEIM2 = 0;
QEICONbits.UP_DOWN = 1;
QEICONbits.ERROR = 0;
QEICONbits.VELM = 1;
ADCON0bits.ADON = 0;
ANSEL0bits.ANS4 = 0;
ANSEL0bits.ANS3 = 0;
ANSEL0bits.ANS2 = 0;
ANSEL0bits.ANS1 = 0;
ANSEL0bits.ANS0 = 0;
LATC = 0;
LATA = 0;
TRISA = 0;
PORTA = 0;
PORTC = 0;
TRISC = 1;
OSCCONbits.IDLEN = 0;


PORTC = CAP1BUFL;


}


Yes, I am fully aware it's not good programming practice to set option registers in the main loop, but it should work. I am also aware that the setting of the registers could be shorter, but I wanted maximum control over the bits so I could get nothing wrong.

Oh, and what does this code do vs what its supposed to? The CAP1CON register sets a capture device that measures PWM duty cycle. From there, the other registers make sure nothing is in the way. Then, PORTC (which is an 8-bit port I have set up with LEDs, and have tested time and time again) is set to the CAP1BUF buffer, where TIMER5's value is supposed to be latched. This is theoretical, since it doesn't work. What does happen is if I initialize CAP1BUF to anything, it will always be that something, and never change, not to mention TMR5 never resets as it should. If I don't ititialize it, it sets itself to a crazy number and the same thing happens. I am dead sure this isn't the microcontroller's fault (I already replaced it once) and the wiring it exactly as it should.

If you'd like the datasheet to see what the registers do, here it is.

Thanks in advance!

Sparks
__________________
ICs do weird things when voltage is run out of spec.

I love to take things apart. The fact that they work better when I put them back together it just a bonus.

http://www.ravenblack.net/random/surreal.html

Last edited by Sparks333 : 22-08-2005 at 13:55.