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.

Mplab Question

Status
Not open for further replies.

binzer

Member
I am trying to run my Junebug in Mplab Debug mode to watch adc data change and to watch the output of some equations.For some reason this seems extremely slow and I think it is because I am missing a setting somewhere. I am using MCC18. Here is the code.

Code:
// JuneBug Info
// Buttons RB0, RB2, RB5.
// Analog AN1, AN3
// IR RB0
// LED's RA0, RA6, RA7
//
// configuration
#pragma*config OSC = INTIO2, WDT = OFF, LVP = OFF, PWRT = ON, BOR = OFF
#include <stdlib.h>
#include <p18f1320.h>
#include <usart.h>
#include <adc.h>
#include <delays.h>
#include <portb.h>


unsigned char config;
unsigned int spbrg;
int reslta0;
int reslta3;
int reslts0;
int reslts3;
char A1;
char B1;


void main(void)
{
	OpenUSART (USART_ASYNCH_MODE &
	USART_TX_INT_OFF &
	USART_RX_INT_OFF &
	USART_EIGHT_BIT &
	USART_CONT_RX &
	USART_BRGH_HIGH,
	25 );

	OpenADC (ADC_FOSC_32 & ADC_RIGHT_JUST & ADC_12_TAD,
	ADC_INT_OFF &  ADC_VREFPLUS_VDD & ADC_VREFMINUS_VSS, 03);
while (1)
{	
	SetChanADC(ADC_CH1);
	Delay10TCYx(5);
	ConvertADC();
	while( BusyADC() );
	reslta0 = ReadADC();
	reslts0 = (reslta0+1)*500/1024;
	itoa (reslts0, A1);

	SetChanADC(ADC_CH3);
	Delay10TCYx(5);
	ConvertADC();
	while( BusyADC() );
	reslta3 = ReadADC();
}	
}
I want to read some ADC channels / etc and send them out the USART, just getting the hang of reading the ADC and converting to readable data for the other end.
Tnx, Mike
 
Last edited:
debugging using pickit2/junebug is "slow" you cannot expect "real time speed", that's the downside of ICD. ICE is much faster (and many times more expensive)...

Have you set a breakpoint or you are doing "step by step". Set breakpoint at the end of the while loop and check the values there, should be much faster.

That aside, you have error in your code:
Code:
...
char A1;
...
itoa (reslts0, A1);
...

itoa second parametar is char array not char, so when you execute this itoa, the address that is contained in A1 variable will be filled with "garbage" making any sort of troubles ...

if you do want to use itoa, change the code to:
Code:
...
char A1[5];
...
itoa (reslts0, A1);
...
 
Try setting the internal clock speed. :)

Code:
void main(void)
{
  // select 8MHz
  OSCCONbits.IRCF0=1;
  OSCCONbits.IRCF1=1;
  OSCCONbits.IRCF2=1;
  
  ....

Thats what I thought was causing part of the problem, not getting the clock speed correct, I wanted 8 or 4 mhz and it's probably at 31khz. I had looked in the Library Routines for that and did not find it. I guess it's somewhat better to do things longhand and know the bits are set over using the Library Routines.

I'll give it another shot in the a.m., back to work now.
Tnx, Mike
 
debugging using pickit2/junebug is "slow" you cannot expect "real time speed", that's the downside of ICD. ICE is much faster (and many times more expensive)...

Have you set a breakpoint or you are doing "step by step". Set breakpoint at the end of the while loop and check the values there, should be much faster.

That aside, you have error in your code:
Code:
...
char A1;
...
itoa (reslts0, A1);
...

itoa second parametar is char array not char, so when you execute this itoa, the address that is contained in A1 variable will be filled with "garbage" making any sort of troubles ...

Yup, I think it was always "0"

if you do want to use itoa, change the code to:
Code:
...
char A1[5];
...
itoa (reslts0, A1);
...

I am a bit rusty on the code end, back to basics after 20yrs away.
Thanks, will get back at it in the a.m. after a couple of coffee's.
Tnx,Mike
 
I'm actually learning C30 currently but I posted a Swordfish BASIC 10bit 4 channel A/D to UART program in JPUG #2.
I saw that. I wanted to get back to using "C", not that basic is bad or anything. I am grabbing snippets here and there to get back into it. I want to write as 'functions' / 'modules' and get them working one by one to get used to working with "C" then put them together for a program.
I want to grab ADC and PORT data from the PIC and sent it down the USART either in a timed fashion or polling for it via the USART.
Wish me luck:)
Thanks, Mike
 
Try setting the internal clock speed. :)

Code:
void main(void)
{
  // select 8MHz
  OSCCONbits.IRCF0=1;
  OSCCONbits.IRCF1=1;
  OSCCONbits.IRCF2=1;
  
  ....

Where can I find a list of these bit settings, been going thru the couple of pdf's that I d/l from Microchip but did not find this info.
Tnx, Mike.
 
They're in the datasheet but always check the include.h file for the chip you're using as it will contain all the register names that the compiler supports for the particular PIC.
 
Last edited:
You have to switch back and forth between the processor data sheet and the processor header file, PIC16F1320.h.

The datasheet tell how it works and the header file contains the names as used by the compiler. You need both.
 
Yup, Got that. It's great for .asm, I also have C18_User Guide & C18_Libraries, but the tidbits posted aren't in there, haven't stopped searchin though..
Exactly what "tidbits" are you looking for? :p

Could it be that you're looking for the C18 header file for 18F1320? You'll find it in "directory_where_you_installed_it\MCC18\h". Most likely C:\MCC18\h
 
Exactly what "tidbits" are you looking for? :p

Could it be that you're looking for the C18 header file for 18F1320? You'll find it in "directory_where_you_installed_it\MCC18\h". Most likely C:\MCC18\h


DUH.! I guess my grey matter is leaking outside too much (skull to hair) and refresh does not occur, and coupling to the optic receptors is a tad bit restricted.:confused:

I found it after the 3rd look, need to print out a couple of files and study.

Maybe it's from smelling all the burned hall effect sensors on the machine I have been working on.

As always, Thanks, Mike.

PS I did get the adc working with the results I calculated/expected.
 
Status
Not open for further replies.

Latest threads

Back
Top