CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

servo cycle variation between s/w and oscilloscope
Goto page Previous  1, 2
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Harry Mueller



Joined: 17 Oct 2005
Posts: 116

View user's profile Send private message

PostPosted: Mon Oct 24, 2005 2:10 pm     Reply with quote

Thanks guys, I've now put it in the main () and most of it works. I've got one issue though and I'd like to know why it's happening. Everything works perfectly until I try to print to the LCD, then then program stops working entirely. No servo, no IR, no LCD. I've also noticed that the LCD print statements add a lot of overhead...they almost triple the program length. Is this normal? Here is the code with the statements that cause the problem REMed out, near the end of the program

Thanks....Harry.
Code:
//This program has a 1500 us pulse with 20 ms period as predicted.
//However, when the LCD print is enabled the program stops working.
//Not sure why at this point.

#include <16F628.h>
#fuses XT, NOWDT, NOPROTECT
#use delay(clock=4000000)
#include <LCD_4LINE.c>   //this file set up to use port B

#define quar_mov 250
#define GP2D02_VIN PIN_B3
#define GP2D02_VOUT PIN_A2

//Long delay function====================================

void long_delay_us(long count)
{
char i;
i = (char)(count >> 8);
while(i >= 1)
{
i--;
delay_us(253);
restart_wdt();
}
delay_us((char)count);
}

//Interrupt Service Routine (ISR)=========================

#int_TIMER0
void servo_isr()
{

//Position the servo(s)===================================

long quarter= 2;
long position;
set_timer0 (100);
position = quarter * quar_mov;
output_high(PIN_A0);
delay_ms(1);
long_delay_us(position);
output_low(PIN_A0);
}

main()
{
  int reading=0;
  int counter=9;
//  lcd_init();
  setup_comparator(NC_NC_NC_NC);
  setup_timer_0(RTCC_INTERNAL | RTCC_DIV_128);
  enable_interrupts(INT_TIMER0);
  enable_interrupts(GLOBAL);

  //Collect the IR reading==================================

   output_low(GP2D02_VIN);         // start cycle with Vin low
   delay_ms(1);                    // give the sensor a little time before we bug it
   while (!input(GP2D02_VOUT));    //wait for Vout to go high
   disable_interrupts(GLOBAL);
   do {
      delay_cycles(4);             // minimum wait is 2us, max is 170us, 4 worked
      output_low(GP2D02_VIN);      // tell the sensor that we want a bit
      delay_cycles(2);             // might be as low as 1 (maybe), 2 worked
      reading=reading<<1;          // left shift the reading value
      reading=reading|(input(GP2D02_VOUT)); // put the newest reading into the
                                            // LSB of reading
      output_high(GP2D02_VIN);     // we read bit, and get ready for the next one
      counter--;
      } while (counter>0);
      enable_interrupts(GLOBAL);

      //LCD print statements====================================
      // Program stops working if this is implemented

//      lcd_gotoxy(1,1);
//      printf(lcd_putc," IR Measurement");
//      lcd_gotoxy(1,2);
//      printf(lcd_putc,"================");
//      lcd_gotoxy(1,3);
//      printf(lcd_putc,"Value = %3u", reading);
//      lcd_gotoxy(1,4);
//      printf(lcd_putc,"Distance = ");

   while(true);
}

Harry Mueller



Joined: 17 Oct 2005
Posts: 116

View user's profile Send private message

PostPosted: Tue Oct 25, 2005 12:35 pm     Reply with quote

Anybody?

I'm trying to develop some servo code for a robotic hexapod and am having some problems. They would be a lot easier to debug if I had the LCD working.

Thanks.....Harry
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Oct 25, 2005 12:42 pm     Reply with quote

Quote:
#include <16F628.h>
#fuses XT, NOWDT, NOPROTECT
#use delay(clock=4000000)
#include <LCD_4LINE.c> //this file set up to use port B


You're using Port B for the LCD. On the 16F628, pin B4 is the PGM pin.
If the chip is in LVP mode (and it is in that mode, as delivered from
the factory), then if you take pin B4 high, the chip will go into Low
Voltage Programming mode and give the appearance of a code lock-up.

Solution:
Add NOLVP to the end of your #fuses statement.

This will be the case for most PICs that you are likely to use.
Harry Mueller



Joined: 17 Oct 2005
Posts: 116

View user's profile Send private message

PostPosted: Tue Oct 25, 2005 2:07 pm     Reply with quote

Thanks PCM, that was it. As soon as I have some time I've got to get into the data sheets for the 16F628.

Harry
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2
Page 2 of 2

 
Jump to:  
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