| 
	
	|  |  |  
	
		| View previous topic :: View next topic |  
		| Author | Message |  
		| Guest 
 
 
 
 
 
 
 
			
			
			
			
			
			
			
			
			
 
 | 
			
				| Take a look ...weird problem |  
				|  Posted: Wed Jan 14, 2009 8:38 am |   |  
				| 
 |  
				| Hello guys ! 
 I'm encountering a strange problem with a otherwise straight forward program. If i'm no mistaken, when 10 ms have passed, pin B0 should go high. Right ?? .... NOPE....NOT HAPPENING !!
 
 Why is that ? Any ideas ?
 
 I'm using CCS C version 4.057.
 
 Here is the code :
 
 
  	  | Code: |  	  | 
 #include <18F452.h>
 #fuses HS,NOWDT,NOPROTECT,NOLVP
 #use delay(clock=4000000)
 #use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
 
 
 char gc_TEST_timer;
 #define TEST_TIMER_TICKS   1
 #define RTCC_PRELOAD 217
 
 
 #INT_RTCC
 void rtcc_isr(void)
 
 {
 set_rtcc(RTCC_PRELOAD);
 
 if (gc_TEST_timer)
 gc_TEST_timer--;
 }
 
 void check_TIMER(void)
 
 {
 if (gc_TEST_timer)
 return;
 else
 
 gc_TEST_timer= TEST_TIMER_TICKS;
 output_high(pin_b0);
 
 }
 
 
 void main()
 {
 gc_TEST_TIMER=TEST_TIMER_TICKS;
 setup_counters(RTCC_INTERNAL, RTCC_DIV_256);
 set_rtcc(RTCC_PRELOAD);
 
 enable_interrupts(INT_RTCC);
 enable_interrupts(GLOBAL);
 
 while(1)
 
 {
 check_timer();
 }
 
 }
 
 
 | 
 
 Cheers !!
 Vasi
 |  |  
		|  |  
		| Ttelmah Guest
 
 
 
 
 
 
 
			
			
			
			
			
			
			
			
			
 
 | 
			
				|  |  
				|  Posted: Wed Jan 14, 2009 9:18 am |   |  
				| 
 |  
				| Timer0. Clocking off 4000000/(256*4) = 3906.25Hz
 Max count 65535 wrapping back to 0 - total 65536  - remember default is 16bit mode.
 Total count time = 16.7 seconds.....
 
 Best Wishes
 |  |  
		|  |  
		| Guest 
 
 
 
 
 
 
 
			
			
			
			
			
			
			
			
			
 
 | 
			
				|  |  
				|  Posted: Wed Jan 14, 2009 9:55 am |   |  
				| 
 |  
				| Ahhhhh...thank you Ttelmah ...yes, the timer0 is 16 bit default. 
 Sorry about this stupid question! I wasn't paying atention !
  |  |  
		|  |  
		| Guest 
 
 
 
 
 
 
 
			
			
			
			
			
			
			
			
			
 
 | 
			
				|  |  
				|  Posted: Wed Jan 14, 2009 10:14 am |   |  
				| 
 |  
				| Here is the CORRECT code ( thank you again  Ttelmah) ! 
 The folowing code applyes in relation to PCM Programer's multitasking program (tank you also, PCM Programer):
 
 
 [/code] 	  | Code: |  	  | 
 #include <18F452.h>
 #fuses HS,NOWDT,NOPROTECT,NOLVP
 #use delay(clock=4000000)
 #use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
 
 
 char gc_TEST_timer;
 #define TEST_TIMER_TICKS   1
 #define RTCC_PRELOAD 217
 
 
 #INT_RTCC
 void rtcc_isr(void)
 
 {
 set_rtcc(RTCC_PRELOAD);
 
 if (gc_TEST_timer)
 gc_TEST_timer--;
 }
 
 void check_TIMER(void)
 
 {
 if (gc_TEST_timer)
 return;
 else
 
 gc_TEST_timer= TEST_TIMER_TICKS;
 output_high(pin_b0);
 
 }
 
 
 void main()
 {
 gc_TEST_TIMER=TEST_TIMER_TICKS;
 setup_timer_0(RTCC_INTERNAL|RTCC_DIV_256|RTCC_8_BIT);
 set_timer0(RTCC_PRELOAD);
 
 enable_interrupts(INT_RTCC);
 enable_interrupts(GLOBAL);
 
 while(1)
 
 {
 check_timer();
 }
 
 }
 
 | 
 |  |  
		|  |  
		| Ttelmah Guest
 
 
 
 
 
 
 
			
			
			
			
			
			
			
			
			
 
 | 
			
				|  |  
				|  Posted: Wed Jan 14, 2009 10:23 am |   |  
				| 
 |  
				| Anyone here, who 'claims' never to have had a moment like this, is lying.... 
   This particular one, is common for people who are used to the 16 chips, where timer0, is only 8bit.
 
 Best Wishes
 |  |  
		|  |  
		| Guest 
 
 
 
 
 
 
 
			
			
			
			
			
			
			
			
			
 
 | 
			
				| Same program - different problem |  
				|  Posted: Thu Jan 15, 2009 12:32 am |   |  
				| 
 |  
				| Hello Ttelmah ! 
 I've got another issue with this code.
 
 One of my tasks is to receive a character over serial and transform it into binary form.
 
 However, the function that returns the character, bgetc(), isn't used properly in the check_SERIAL() function.
 If my C knowledge is correct, is should have worked !!
   
 Here is the code in question:
 
 
  	  | Code: |  	  | 
 #int_rda
 void serial_isr() {
 int t;
 output_toggle(pin_b1);   //debug
 buffer[next_in]=getc();
 t=next_in;
 next_in=(next_in+1) % BUFFER_SIZE;
 if(next_in==next_out)
 next_in=t;           // Buffer full !!
 }
 
 BYTE bgetc() {
 BYTE c;
 
 output_toggle(pin_b2); // debug
 while(!bkbhit) ;
 c=buffer[next_out];
 next_out=(next_out+1) % BUFFER_SIZE;
 return(c);
 }
 
 void check_SERIAL( void)
 {
 char i,d;
 
 if(gc_IRTRANSMIT_timer)
 {
 output_toggle(pin_b3);
 return;
 }
 else
 
 {
 
 gc_IRTRANSMIT_timer  = IRTRANSMIT_TIMER_TICKS;
 output_toggle(pin_b4);  //debug
 for(i = 0; i < 8; i++)
 {
 output_toggle(pin_b5); //debug
 if( bgetc() & 0x80)
 d='1';
 else
 d='0';
 bgetc() <<= 1;
 cmd[i]=d;
 }
 cmd[8]=0;
 output_toggle(pin_b6); //debug
 
 printf("%s",cmd);
 }
 }
 
 | 
 
 Any ideas/hints ??
 |  |  
		|  |  
		| Guest 
 
 
 
 
 
 
 
			
			
			
			
			
			
			
			
			
 
 | 
			
				|  |  
				|  Posted: Thu Jan 15, 2009 12:33 am |   |  
				| 
 |  
				| P.S.: I'm using PIC18f452 @ 10 MHZ and CCS C version 4.057 
 Thank You !!
 |  |  
		|  |  
		| Guest 
 
 
 
 
 
 
 
			
			
			
			
			
			
			
			
			
 
 | 
			
				|  |  
				|  Posted: Thu Jan 15, 2009 12:37 am |   |  
				| 
 |  
				| I've tried another solution. 
 In the original post, PCM Programmer said the following things :
 
 
  	  | Quote: |  	  | 
 // Check the interrupt-driven software fifo here,
 // to see if any characters are in the buffer.
 // If so, handle them.   See  EX_SISR.C for
 // an example of how to do the software fifo.
 // Make the size of the fifo be large enough,
 // so that it doesn't overflow between the
 // times that you come into this task to check it.
 // Or, set the gc_IRTRANSMIT_timer value to a lower
 // value, so that you check the fifo sufficiently often.
 
 // Once you've read the characters, then put
 // code here to act on them.  If it's a command
 // sent through the serial port, then set a global
 // flag.  Then, one of the other tasks can read
 // the flag and it can do something -- perhaps
 // it could start a complex sequence of LED blinking.
 // (It would also clear the global flag).
 
 | 
 
 So...i've tried the code in the following way :
 
 
  	  | Code: |  	  | 
 void check_IRTRANSMIT( void)
 {
 char c,i,d;
 
 if(gc_IRTRANSMIT_timer)
 {
 output_toggle(pin_b3);
 return;
 }
 else
 
 {
 
 gc_IRTRANSMIT_timer  = IRTRANSMIT_TIMER_TICKS;
 output_toggle(pin_b4);
 while(!bkbhit) ;
 c=buffer[next_out];
 next_out=(next_out+1) % BUFFER_SIZE;
 
 for(i = 0; i < 8; i++)
 {
 output_toggle(pin_b5); //debug
 if( c & 0x80)
 d='1';
 else
 d='0';
 c <<= 1;
 cmd[i]=d;
 }
 cmd[8]=0;
 output_toggle(pin_b6); //debug
 
 printf("%s",cmd);
 }
 
 
 | 
 
 Still no succes ...... HMMMM
 
 Please help me !!!!!!!!
 |  |  
		|  |  
		| Wayne_ 
 
 
 Joined: 10 Oct 2007
 Posts: 681
 
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Thu Jan 15, 2009 3:21 am |   |  
				| 
 |  
				| You were close 
 
  	  | Code: |  	  | void check_IRTRANSMIT( void)
 {
 char c,i,d;
 
 if(gc_IRTRANSMIT_timer)
 {
 output_toggle(pin_b3);
 return;
 }
 else
 
 {
 // Does it definately get here ?
 gc_IRTRANSMIT_timer  = IRTRANSMIT_TIMER_TICKS;
 output_toggle(pin_b4);
 
 c = bgetc();  // Need to get 1 8bit value, use bgetc
 
 for(i = 0; i < 8; i++)
 {
 output_toggle(pin_b5); //debug
 if( c & 0x80)
 d='1';
 else
 d='0';
 c <<= 1;
 cmd[i]=d;
 }
 cmd[8]=0;  // I assume cmd is defined as char cmd[9];
 output_toggle(pin_b6); //debug
 
 printf("%s",cmd);  // What DOES it output ?
 }
 
 
 | 
 
 If you read my comments you will notice you have missed a few vital bits of info to help us debug this.
 
 
 Change c = bgetc(); to c = 0xAA; and see if you get 10101010
 Chage to different values and see if you get the correct value.
 
 If bgetc does not work but c=n; does then the problem lies with your serial routines/interface.
 Try
 c = bgetc();
 printf("%c", c);
 
 to see exactly what it is.
 Also put printf("Start\r\n");
 at the start of your code to make sure your serial output works.
 |  |  
		|  |  
		| Guest 
 
 
 
 
 
 
 
			
			
			
			
			
			
			
			
			
 
 | 
			
				|  |  
				|  Posted: Thu Jan 15, 2009 4:15 am |   |  
				| 
 |  
				| Hello Wayne_ ! 
 HUH ....A stupid mistake was the cause of this error. I've forgotten to enable the RDA interrupt.
 
 Ufffffffffffffffffff..... Thank you Wayne_ ! I've noticed this when i was trying to copy the program to post it here.
  |  |  
		|  |  
		|  |  
  
	| 
 
 | 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
 
 |