Go to Post The best teams have students who genuinely enjoy scouting and the alliance selection process. - Jay O'Donnell [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 16-08-2005, 02:11
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
PIC 18F2431

Hello!
I recently purchased a PIC 18F2431 from Microchip for the express purpose of reading a pwm signal. The 18Fxx31 series have a special CAPx feature in the Motion Feedback Module that can measure the PWM signal using a timer and some edge-triggering hardware, but I cannot get the buffer where the timer gives its output for the pulse width to update: it simply stays where I initialized it. I have gone through the configuration bits so many times it isn't even funny, and tried more programming techniques than I have resistors (that's a lot!) and still cannot get it to work. Furthermore, I replaced the microprocessor, and it CONTINUES TO DEFY ME!!!! ARGH!!!
sorry.
In short, I have tested every piece of the module, from the timer to the input pins, and still it does not work. It is very difficult for me to post my programs, because it has many obscure references to buffers nonexistent in other microcontrollers. If anyone has any experience with this type of PIC, please respond!

Thanks!

Sparks333
__________________
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
  #2   Spotlight this post!  
Unread 16-08-2005, 09:51
Unsung FIRST Hero
Mike Betts Mike Betts is offline
Electrical Engineer
no team
Team Role: Engineer
 
Join Date: Dec 2001
Rookie Year: 1995
Location: Homosassa, FL
Posts: 1,442
Mike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond repute
Re: PIC 18F2431

Dane,

Have you been able to get your code to work under simulation (MPLAB SIM)?

Mike
__________________
Mike Betts

Alumnus, Team 3518, Panthrobots, 2011
Alumnus, Team 177, Bobcat Robotics, 1995 - 2010
LRI, Connecticut Regional, 2007-2010
LRI, WPI Regional, 2009 - 2010
RI, South Florida Regional, 2012 - 2013

As easy as 355/113...
  #3   Spotlight this post!  
Unread 16-08-2005, 10:49
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

nope. I've also used the watch window to see if the CAPxBUF buffer ever changes. No joy.

Sparks333
__________________
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
  #4   Spotlight this post!  
Unread 16-08-2005, 11:41
Gdeaver Gdeaver is offline
Registered User
FRC #1640
Team Role: Mentor
 
Join Date: Mar 2004
Rookie Year: 2001
Location: West Chester, Pa.
Posts: 1,367
Gdeaver has a reputation beyond reputeGdeaver has a reputation beyond reputeGdeaver has a reputation beyond reputeGdeaver has a reputation beyond reputeGdeaver has a reputation beyond reputeGdeaver has a reputation beyond reputeGdeaver has a reputation beyond reputeGdeaver has a reputation beyond reputeGdeaver has a reputation beyond reputeGdeaver has a reputation beyond reputeGdeaver has a reputation beyond repute
Re: PIC 18F2431

Can you post some code snips of setting the registers and details of the signal your trying to measure?
  #5   Spotlight this post!  
Unread 16-08-2005, 14:18
Unsung FIRST Hero
Mike Betts Mike Betts is offline
Electrical Engineer
no team
Team Role: Engineer
 
Join Date: Dec 2001
Rookie Year: 1995
Location: Homosassa, FL
Posts: 1,442
Mike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond repute
Re: PIC 18F2431

Quote:
Originally Posted by Sparks333
nope. I've also used the watch window to see if the CAPxBUF buffer ever changes. No joy.

Sparks333
Dane,

I strongly suggest that you watch the web seminar "Introduction to MPLABŪ SIM Software Simulator" presented by Darrel Johansen at this site. Pay particular attention to his discussion of the Stimulus Controller.

Peace,

Mike
__________________
Mike Betts

Alumnus, Team 3518, Panthrobots, 2011
Alumnus, Team 177, Bobcat Robotics, 1995 - 2010
LRI, Connecticut Regional, 2007-2010
LRI, WPI Regional, 2009 - 2010
RI, South Florida Regional, 2012 - 2013

As easy as 355/113...
  #6   Spotlight this post!  
Unread 16-08-2005, 15:39
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

Mike,
thanks for the link. I will definitely go in deeper once I get a spare minute.

Gdeaver,
The signal I am trying to capture is a 200khz PWM signal from a Memsic thermal inclimometer. Isn't that a mouthful? I am on the wrong computer to give code, but I'll put them on as soon as I can.

Sparks333
__________________
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
  #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.
  #8   Spotlight this post!  
Unread 22-08-2005, 23:56
Unsung FIRST Hero
Mike Betts Mike Betts is offline
Electrical Engineer
no team
Team Role: Engineer
 
Join Date: Dec 2001
Rookie Year: 1995
Location: Homosassa, FL
Posts: 1,442
Mike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond repute
Re: PIC 18F2431

Quote:
Originally Posted by Sparks333
...Yes, I am fully aware it's not good programming practice to set option registers in the main loop, but it should work...

...What does happen is if I initialize CAP1BUF to anything, it will always be that something, and never change...
Dane,

Absolutely, definitely change the initialization to be done once and once only.

As an example, you are setting CAP1BUF to zero every time through the loop. Except for a brief microsecond or two, why would it ever be anything else?

Mike
__________________
Mike Betts

Alumnus, Team 3518, Panthrobots, 2011
Alumnus, Team 177, Bobcat Robotics, 1995 - 2010
LRI, Connecticut Regional, 2007-2010
LRI, WPI Regional, 2009 - 2010
RI, South Florida Regional, 2012 - 2013

As easy as 355/113...
  #9   Spotlight this post!  
Unread 23-08-2005, 13:55
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

Mike,
This particular code is a revision, to test to see if the CAP1BUFL ever did become anything except the initailization.. In earlier versions, I did not initalize CAP1BUFL, allowing it to at first float, then become whatever it should be assigned to. Sadly, the program did exactly the same thing. I will remove it, but it makes no difference. However, you do bring up a good point. I am now wondering if continually resetting configuration buffers resets CAP1BUFL? There was nothing about that in the documentation...

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 : 23-08-2005 at 13:57.
  #10   Spotlight this post!  
Unread 24-08-2005, 01:24
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

Everyone:
I found the problem, and it had nothing at all to do with the program. Not even the config bits. The problem was with the sensor itself. The PIC was pulling more current than the sensor could put out, and so the pulse 'highs' were being pulled to almost ground, so the device could not read the pulses as occuring. Throw in an NPN transistor, and the whole thing was working fine. Thanks for all your time, especially Mike Betts.
This post can now languish into obscurity.

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
Closed Thread


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Linux and new microcontollers. djcapelis Programming 48 29-01-2005 00:26
Learning PIC C Adam Collet Programming 18 19-10-2003 19:36
PIC Programmers seanwitte Electrical 8 18-04-2003 17:04
Who am I pic... Pamela CD Forum Support 6 23-07-2001 23:49


All times are GMT -5. The time now is 09:50.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi