  | 
	  | 
		 
	 
	
		| View previous topic :: View next topic   | 
	 
	
	
		| Author | 
		Message | 
	 
	
		
			Jack// ani Guest
 
 
 
 
  
			
			
			
			
			
			
			
			
			
			
  
		  | 
		
			
				| Trouble with VREF_HIGH | 
			 
			
				 Posted: Mon Apr 25, 2005 8:47 am     | 
				     | 
			 
			
				
  | 
			 
			
				Hi all,
 
 
When I try to compile this program, I get this error “Undefined Identifier VREF_HIGH”. Can’t understand the problem, even EX_COMP.C which is example program from CCS PIC C gives a similar error! Please tell me what this line means setup_comparator(A0_A3_A1_A2);.
 
 
 
#include <16F628.h>
 
#fuses XT,WDT,NOPROTECT
 
#use delay(clock=4000000)
 
#use rs232(baud=9200, xmit=PIN_A3, rcv=PIN_A4)
 
 
short safe_conditions=TRUE;
 
 
#INT_COMP
 
void isr()  {
 
 
   safe_conditions=FALSE;
 
   printf("WARNING!!  Voltage level is above 3.6 V.   \r\n");
 
}
 
 
 
main()   {
 
 
   printf("\r\nRunning voltage test...\r\n\n");
 
 
   setup_comparator(A0_A3_A1_A2);
 
   setup_vref(VREF_HIGH|15);
 
   enable_interrupts(INT_COMP);
 
   enable_interrupts(GLOBAL);
 
 
 
   while(TRUE)
 
   {
 
      if(safe_conditions)
 
         printf("Voltage level is below 3.6 V.              \r\n");
 
      safe_conditions=TRUE;
 
      delay_ms(500);
 
   }
 
}
 
 
Thanks | 
			 
		  | 
	 
	
		  | 
	 
	
		
			PCM programmer
 
 
  Joined: 06 Sep 2003 Posts: 21708
  
			
			 
			 
			
			
			
			
			
			
			
  
		  | 
		
			
				 | 
			 
			
				 Posted: Mon Apr 25, 2005 12:27 pm     | 
				     | 
			 
			
				
  | 
			 
			
				What is your version of the compiler ?
 
 
To find the version, compile a file (with errors), and look at the
 
top of the .LST file.   The version will be a number like 3.191, 3.223, etc. | 
			 
		  | 
	 
	
		  | 
	 
	
		
			Jack// ani Guest
 
 
 
 
  
			
			
			
			
			
			
			
			
			
			
  
		  | 
		
			
				 | 
			 
			
				 Posted: Mon Apr 25, 2005 11:27 pm     | 
				     | 
			 
			
				
  | 
			 
			
				| CCS PCM C Compiler, Version 3.200 | 
			 
		  | 
	 
	
		  | 
	 
	
		
			PCM programmer
 
 
  Joined: 06 Sep 2003 Posts: 21708
  
			
			 
			 
			
			
			
			
			
			
			
  
		  | 
		
			
				 | 
			 
			
				 Posted: Tue Apr 26, 2005 12:06 am     | 
				     | 
			 
			
				
  | 
			 
			
				Your 16F628.H file is missing the VREF constant declarations.
 
Somehow, they were left out of your version.
 
Add the following code below the #use statements in your program.
 
 	  | Code: | 	 		  
 
// Constants used in setup_vref() are:
 
//
 
#define VREF_LOW  0xa0
 
#define VREF_HIGH 0x80
 
// Or (with |) the above with a number 0-15
 
#define VREF_A2   0x40
 
 | 	  
 
I have a few comments on the rest of your program.
 
 
In the #fuses statement, you have enabled the Watchdog Timer,
 
but you don't have any restart_wdt() statements in your code.
 
I suggest that you disable it with NOWDT in the #fuses statement.
 
 
Also, you really should have NOLVP at the end of your #fuses
 
statement.   If you don't you risk having your program lock-up
 
if PIN_B4 goes high.   This is the PGM pin and is used for LVP 
 
programming.
 
 
In your #use rs232() statement, you're using a non-standard baud
 
rate of 9200.   Almost certainly, you really want to use 9600.
 
In addition, you are using pins A3 and A4 for the UART.    The compiler
 
will create a software UART for those pins.   But the 16F628 has a
 
hardware UART.   That's part of it's "claim to fame".   It's cheap but
 
it has a hardware UART.  So why not use it ?   A better way to do it
 
would be: 
 
 	  | Code: | 	 		  | #use rs232(baud=9600, xmit=PIN_B2, rcv=PIN_B1, ERRORS) | 	  
 
In your #INT_COMP routine, you're not clearing the mismatch condition.
 
You need to do this at the end of the routine, by reading the CMCON
 
register.   You need to do it this way:
 
 	  | Code: | 	 		  #byte CMCON = 0x1F
 
 
#INT_COMP 
 
void isr()
 
{ 
 
char c;
 
safe_conditions=FALSE; 
 
c = CMCON;
 
}  | 	  
 
Also normally you don't do printf() inside an isr because it locks up
 
the program from using any interrupts for the amount of time it
 
takes to transmit all those bytes.  
 
 
There may be more things wrong that I didn't see or post.
 
 
In addition, CCS did a moderately major change to compiler starting
 
with vs. 3.200.   Any version in the low 3.2xx series is going to be buggy.
 
Your version might be the most buggy of them.   Just a warning. | 
			 
		  | 
	 
	
		  | 
	 
	
		 | 
	 
 
  
	 
	    
	   | 
	
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
  | 
   
 
  
Powered by phpBB © 2001, 2005 phpBB Group
  
		 |