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.

Understanding Fosc (PIC18F4620)

Status
Not open for further replies.
Yes LEDs blink every second (or is it half a sec)
 

Is the "Configuration Bits set in code" check box checked?

If so comment out the following line:

#pragma config OSC=INTIO67, LVP=OFF, MCLRE=ON , WDT=OFF

Uncheck the "Configuration Bits set in code" check box and set the configuration bits to the settings above in the Configuration Bits Window.

See if you get the same delay with the blinking lights.

BigDog
 

Now replace the contents of the C file with the following:

Code:
#include <p18f4620.h>
#include <usart.h>
#include <delays.h>

 
// INTIO67 configures internal oscillator
//#pragma config OSC=INTIO67, LVP=OFF, MCLRE=ON , WDT=OFF
 
void setup(void)
{
	/* Clock Setup*/ 
	OSCCON = 0b01110010; //select 8 MHz clock 

	/* Port Set Up*/
	ADCON1 = 0b00001111; //set all pins to digital mode
	TRISD = 0x00;
	TRISA = 0x00;
	TRISB = 0b00000000; 
	TRISC = 0b10000000; // RX is an input, TX is output


	/* Interrupt Setup */
	INTCON = 0x00; /* Clear Registers */
	PIR1 = 0x00;
	PIE1 = 0x00;
	

  // Turn on the 4 LEDs
 // Microchip recommends writing to the PORT Latch rather than the PORT Pins 
	LATBbits.LATB0=1;
	LATBbits.LATB1=1;
	LATBbits.LATB2=1;
	LATBbits.LATB3=1;

    


	
 
}	
 

void main(void)
{
    int n = 12;

	setup();

  while(1)
  {
	while (n--)
	{
	
		Delay10KTCYx(100);

                // Blink the 4 LEDs
               // Microchip recommends writing to the PORT Latch rather than the PORT Pins 
	       LATBbits.LATB0 = ~LATBbits.LATB0;
	       LATBbits.LATB1 = ~LATBbits.LATB1;
	       LATBbits.LATB2 = ~LATBbits.LATB2;
	       LATBbits.LATB3 = ~LATBbits.LATB3;

		
	}

   OpenUSART (USART_TX_INT_OFF & USART_RX_INT_OFF & USART_ASYNCH_MODE & USART_EIGHT_BIT & USART_CONT_RX & USART_BRGH_LOW, 12);

   n = 150;

	while (n--)
	{
	
		Delay10KTCYx(100);

        putrsUSART(" Hello World! ");
	

		
	}

    CloseUSART();
  }

}

Notice I've left the configuration bit setting to be done in MPLAB in the configuration bit window.

BigDog
 

LEDs blink 6 times and for the USART "Cannot open COM3. Please check your port settings"

After a minute or so LEDs start blinking again, this time forever!
 

Where exactly are you receiving this message, "Cannot open COM3. Please check your port settings", is it your terminal emulator, Hyperterminal?

BigDog
 

Yes, Hyperterminal. I tried Putty as you suggested before, that doesnt even open up anything!

 

Here is my project, try programming the PIC with my HEX file without recompiling. Zip up your project and upload to the thread and I will try the same.

BigDog
 

Attachments

  • Neyolight2.zip
    29 KB · Views: 73

Allright, heres what I have
 

Attachments

  • Try.zip
    20.9 KB · Views: 63

Your hex file blinks the LEDs 6 times and then it turns off the LEDs( except for RB2, for some strange reason its always on when nothing is written to the LEDS) , the hyperterimal connects but nothing is written on to it!
 

If I import either your original HEX or COFF file and then program the PIC, both work fine. However, if you open the project up and then program the PIC, neither work.

What is your report?

BigDog
 

I want to try Neyolight3 but the program(Pickit 3) isnt starting! I restarted the computer , but no luck! :|

On top of that, getting yelled by fellow colleagues to go home ! Will check the 3rd version when I get home today! Thanks though =)

---------- Post added at 17:21 ---------- Previous post was at 17:17 ----------

Ok ignore my previous message, I just tried Neyolight 3 and it gives me an error "unable to open comport3, check your port settings"
 

However, if you open the project up and then program the PIC, neither work.

BigDog

You mean without opening MPLAB, the file I sent you worked but when you programmed through MPLAB it didn't?
 

This morning I got a new PIC18f4620 and installed in my board, Same error ! I think I will switch to a PIC16 and HIGH-TEC C now !

---------- Post added at 10:13 ---------- Previous post was at 09:49 ----------

Ok so I have some new info to share on this issue. I went back to perform a loop back test on the board. I took the PIC out and connected Tx and Rx on the DIP and as expected it worked fine!

Test1: Nothing connected to Tx and Rx. I used AccessPort to send "This is test" to the board, but since the two pins ( Tx and Rx) arents connected, we shouldnt get anything back right? But to my surprise I got this( see image below). Is this just noise or what exactly is it? Btw test result is not repetitive- sort of like one off!



Test 2: I connected wire to Tx and left thr other end open. I got this ( see pic below) . Is that just noise? This test result is repetitive! Also when I "stop send" , the lines still keeps going. Its constantly sending these "dots" to PC !
 
Last edited:

You mean without opening MPLAB, the file I sent you worked but when you programmed through MPLAB it didn't?

Without opening the project file, I instead imported the HEX or COFF file into MPLAB, then used an ICD to program the PIC. Both of your files were successful. However, if I tried to program the PIC after opening the project file in MPLAB, neither would perform as expected. This is most likely due to the differences between the programming device, PICKIT for you and ICD for myself.

BigDog

---------- Post added at 22:38 ---------- Previous post was at 22:28 ----------

This morning I got a new PIC18f4620 and installed in my board, Same error ! I think I will switch to a PIC16 and HIGH-TEC C now !

Let me know if you experience and better performance from the HiTech Compiler. Maybe I send you a HEX file for a PIC16 you have available.




Ok so I have some new info to share on this issue. I went back to perform a loop back test on the board. I took the PIC out and connected Tx and Rx on the DIP and as expected it worked fine!

Test1: Nothing connected to Tx and Rx. I used AccessPort to send "This is test" to the board, but since the two pins ( Tx and Rx) arents connected, we shouldnt get anything back right? But to my surprise I got this( see image below). Is this just noise or what exactly is it? Btw test result is not repetitive- sort of like one off!



Test 2: I connected wire to Tx and left thr other end open. I got this ( see pic below) . Is that just noise? This test result is repetitive! Also when I "stop send" , the lines still keeps going. Its constantly sending these "dots" to PC !

These results do not surprise me. Ungrounded inputs in close proximity to an oscillator can easily receive copious amounts of noise. The loopback test seems to verify that the MAXIM RS-232 Transceiver is not misbehaving. Try similar test code for a PIC16 and report back the results.

Actually check out these excellent PIC tutorials for both Baseline and Midrange PICs using the HiTech C Compiler:

**broken link removed**

BigDog

---------- Post added at 22:38 ---------- Previous post was at 22:38 ----------

This morning I got a new PIC18f4620 and installed in my board, Same error ! I think I will switch to a PIC16 and HIGH-TEC C now !

Let me know if you experience and better performance from the HiTech Compiler. Maybe I send you a HEX file for a PIC16 you have available.




Ok so I have some new info to share on this issue. I went back to perform a loop back test on the board. I took the PIC out and connected Tx and Rx on the DIP and as expected it worked fine!

Test1: Nothing connected to Tx and Rx. I used AccessPort to send "This is test" to the board, but since the two pins ( Tx and Rx) arents connected, we shouldnt get anything back right? But to my surprise I got this( see image below). Is this just noise or what exactly is it? Btw test result is not repetitive- sort of like one off!



Test 2: I connected wire to Tx and left thr other end open. I got this ( see pic below) . Is that just noise? This test result is repetitive! Also when I "stop send" , the lines still keeps going. Its constantly sending these "dots" to PC !

These results do not surprise me. Ungrounded inputs in close proximity to an oscillator can easily receive copious amounts of noise. The loopback test seems to verify that the MAXIM RS-232 Transceiver is not misbehaving. Try similar test code for a PIC16 and report back the results.

Actually check out these excellent PIC tutorials for both Baseline and Midrange PICs using the HiTech C Compiler:

**broken link removed**

BigDog
 
I have a PIC16F1937 that originally came with the board. Guess its time to learn a new PIC!
 

Interesting the PICDEM2 Plus boards originally shipped with a 16F877A. I probably have some thing close to a PIC16F1937 if not that particular variant.

BigDog
 

Hello bigdogguru - A very Happy new year to you!

I just got back from holidays and giving a last chance to the codes here! I have a new finding, using "realterm" i get a different error : break condition received!

Google : "RS232-C also specifies a signal called a Break, which is caused by sending continuous Spacing values (no Start or Stop bits). When there is no electricity present on the data circuit, the line is considered to be sending Break."

So im just wondering if there is a need to specify the STOP bit in the code? I used Stop bit = 1 in the emulator though

Heres the code
Code:
#include <p18f4620.h>
#include <stdio.h>
#include <delays.h>
#include <usart.h>
 
// INTIO67 configures internal oscillator
#pragma config OSC=INTIO67, LVP=OFF, MCLRE=ON , WDT=OFF
 
void setup(void)
{
	/* Clock Setup*/ 
	OSCCON = 0b01110010; //select 8 MHz clock 

	/* Port Set Up*/
	ADCON1 = 0b00001111; //set all pins to digital mode
	TRISD = 0x00;
	TRISA = 0x00;
	TRISB = 0b00000000; 
	TRISC = 0b10000000; // RX is an input, TX is output

 
 // Turn on the 4 LEDs
 // Microchip recommends writing to the PORT Latch rather than the PORT Pins 
	LATBbits.LATB0=1;
	LATBbits.LATB1=1;
	LATBbits.LATB2=1;
	LATBbits.LATB3=1;

 	
	/* Interrupt Setup */
	INTCON = 0x00; /* Clear Registers */
	PIR1 = 0x00;
	PIE1 = 0x00;
	TMR1L = 0x00;
	TMR1H = 0x00;
	T1CON = 0x00;
	RCON = 0x00; 

	

    /* RS232 Enable */
	// OpenUSART Configures The Next Three Lines
	//RCSTA = 0b10000000;
	//TXSTA = 0b00100000;
	//BAUDCON = 0b01000000;
		
	// USART 9600 8-N-1
	OpenUSART (USART_TX_INT_OFF & USART_RX_INT_OFF & USART_ASYNCH_MODE & USART_EIGHT_BIT & USART_CONT_RX & USART_BRGH_LOW, 12);
 
}	
 

#pragma code
void main(void)
{
	setup();
		
	while (1)
	{
	
		putrsUSART(" Hello World! ");
		//while(BusyUSART());
		Delay10KTCYx(100);
		
	}
}

Thanks

---------- Post added at 09:39 ---------- Previous post was at 09:34 ----------

And at other time i get this new error with "real term" : Apro exception"
 

Heya
The code FINALLY works! =D After struggling for more than a month, IT FINALLY WORKS ! Ive never been so happy in my life :p

I pulled out Jumper J20 and J21 and the code works ! ( the first time code worked with the 2 jumpers on though) I now have J20-J23 out !

Thanks Bigdogguru for all the help!
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top