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

help for project & Proteus.

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Gio
Guest







help for project & Proteus.
PostPosted: Mon Nov 30, 2009 2:59 am     Reply with quote

I am working to a project for the management of an antenna rotor by rs232, using Proteus for the simulation.
I am using a 16f877a and my project have WATCHDOG, rs232 INT:, timer1 INT., ADC ecc. , see part of code:
Code:

#include <16F877a.h>
#device *=16
#device adc=10
#fuses WDT,HS, PUT, NOPROTECT, NOLVP

#define ClockSpeed 10000000
#use delay(clock=ClockSpeed)

..........

//------------------
#INT_TIMER1
//------------------
// This function is called every time the timer overflows.
void Timer1_int(void)
{
   set_timer1(TIMER1_INI_VALUE);

   if (--int_count100ms == 0) // Scaduti 100ms
   {
      int_count100ms = INTS_PER_100ms;

      // if rotor is On but not change position
      if ((Rotor.MotorRight == ON || Rotor.MotorLeft == ON) && (Old_DegPos_AZ == DegPos_AZ))
      {
         ++RotorJamCount;
      }
      else
      {
         RotorJamCount = 0;
      }
      Old_DegPos_AZ = DegPos_AZ;

      if (--Counter100ms == 0)   // scaduto 1 secondo
      {
         Counter100ms = 10;
         ++Counter1s;
      }
      if (_delay100ms > 0)  // count 10ms intervals
         _delay100ms--;

   }
   if (_delay10ms > 0)  // count 10ms intervals
      _delay10ms--;
}



//--------------------------------
// RS232 receive interrupt
#int_rda
void serial_isr()
//--------------------------------
{
int tmp;

   RX_buffer[next_in] = fgetc(PC);
   tmp = next_in;
   next_in = (next_in+1) % BUFFER_SIZE;
   if(next_in == next_out)
     next_in = tmp;           // Buffer full !!
}

......

/--------------------------------
void main()
//--------------------------------
{
int8 restart_reason;

   restart_reason = restart_cause();


   setup_wdt(WDT_2304MS);
   restart_wdt();

   int_count100ms = INTS_PER_100ms;
   Counter1s = 0;
   Counter100ms = 10;

   setup_timer_1 ( T1_INTERNAL | T1_DIV_BY_8 );
   set_timer1(TIMER1_INI_VALUE);

   setup_ccp1(CCP_PWM);
   // The cycle time will be  (1/ clock  )   * 4 * t2div * (period + 1)
   // The cycle time is:      (1/10.000.000) * 4 * 1     * (127 + 1   ) = 51.2 us or 19.5 khz
   // setup_timer_2 (mode, period, postscale)
   setup_timer_2(T2_DIV_BY_1, 127, 1);


   setup_adc_ports(RA0_RA1_RA3_ANALOG);
   setup_adc(ADC_CLOCK_INTERNAL);

   CLEAR_INTERRUPT(INT_RDA);
   enable_interrupts(INT_RDA);
   enable_interrupts(INT_TIMER1);
   enable_interrupts(global);

   port_b_pullups(true);

   #use fast_io(A)
   #use fast_io(B)

   set_pwm1_duty(0);

   Motor_Az_OFF();

   SET_TRIS_A(0b00001011);   // set port:   1 = INPUT   0 = OUTPUT
   SET_TRIS_B(0b11110000);   // set port:   1 = INPUT   0 = OUTPUT
   SET_TRIS_C(0b10000000);    // set port:   1 = INPUT   0 = OUTPUT

   lcd_init();

   Check_restart(restart_reason);

 OFFSet      = 1;
   AZ_RANGE    = 360;
   ADC_AZ_Ini  = 5;
   ADC_AZ_End  = 914;
   AZ_Mul_end = ((float) (ADC_AZ_End - ADC_AZ_Ini)) / (float) AZ_RANGE;

   DegPos_AZ  = ADC_to_DEG (CH_AZ, ADC_AZ_Ini, AZ_Mul_End);
   DegReq_AZ = DegPos_AZ;
   
   lcd_clear;
   lcd_putc("Req Az:");
   lcd_gotoxy(1,2);
   lcd_putc("Cur Az:");

     Display_position(1, DegReq_AZ);


   while (TRUE)
      {

      while (isempty(next_in, next_out))  // Here do stuff while waiting for the serial
         {

         //§ SetAzRotorSpeed();

         // This sets the time the pulse is high each cycle.
         //  if value is LONG INT:  value *     (1/clock) * t2div
         //  if value is INT:       value * 4 * (1/clock) * t2div
         // WARNING:  A value too high or low will prevent the output from changing.
         set_pwm1_duty(AzRotorSpeed);   //§


         restart_wdt();

         req_pos_ant();

         Motor_Azimut();

          Display_position(1, DegReq_AZ);

         lcd_gotoxy(13,1);
         printf(LCD_PUTC, "%1u", RotorJamCount/10);

         Display_position(2, DegPos_AZ);
         }

      // Here a character is ready.
      restart_wdt();

      trt_gs232();
      }
}

Everything was ok up to when I have not added a PWM. From that moment the simulation with Proteus has become slow, also 15 seconds or more to notice the pressure of a key.

I have not understood if it is a tied up problem to the simulation with Proteus, if the activation of the PWM interferes with the other resources of the PIC, or if it is one error of my code.

Thank in advance for any help.

Gio
pdl



Joined: 01 Jun 2005
Posts: 45
Location: UK

View user's profile Send private message

PostPosted: Mon Nov 30, 2009 6:06 am     Reply with quote

Try it in the real world, Make the circuit.

I used Proteus on some code and found that it would hang so i made the circuit and programmed a Pic.

thanks

Pete
Jo



Joined: 12 Oct 2009
Posts: 6

View user's profile Send private message

help for project & Proteus.
PostPosted: Wed Dec 02, 2009 8:19 am     Reply with quote

Hello Gio
Can you indicate the full code of your project, enclosed some info
about the electric scheme ? I'm studying a similar project.
Thanks
Jo
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
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