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 support@ccsinfo.com

Proteus error messages with CCS

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



Joined: 12 Apr 2013
Posts: 24

View user's profile Send private message

Proteus error messages with CCS
PostPosted: Fri Apr 12, 2013 6:31 am     Reply with quote

Hello i am trying to make a frequency and volt meter with PIC16F877A (20 MHz crystal and 22pF capacitors) using the CCS ex_freqc.c and the FLEX420_LCD.C . Proteus " Logic Connection(s) detected on net#00001, net"00002 , 00003 and also on net#00004.
I have the frequency input connected to RC0 and the voltage at RA0
It seems that every frequency i try to input in Proteus above 3000 Hz with VSFFM gives me also an error that simulation is not in real time due to cpu overload thought if i wait long enough it still will display the frequency. Also weirdly all the time the frequency is displayed with a number 3 times bigger ( but i think thats only trouble in the simulation and in real it will not be 3x number).


I have set the port layout in FLEX420 :

Code:
#define LCD_DB4   PIN_B4
#define LCD_DB5   PIN_B5
#define LCD_DB6   PIN_B6
#define LCD_DB7   PIN_B7

#define LCD_RS    PIN_B0
#define LCD_RW    PIN_B1
#define LCD_E     PIN_B2


and my main source code is

Code:

#include <16F877A.h>
#device adc=10    // za adc volt
#fuses HS,NOWDT,NOLVP
#use delay(clock=20000000)    //one instruction=0.2us
#use rs232(baud=9600, xmit=PIN_c6, rcv=PIN_c7)
#bit t1_overflow=0x0C.0
#include <FLEX_LCD420.c>

// #bit t1_overflow=0xF9E.0  (PIC18, Reminder)


//unsigned int16 value;  // za volt

void main() {
 
 // The lcd_init() function should always be called once,
// near the start of your program.
lcd_init();

// Clear the LCD.
printf(lcd_putc, "\f");
delay_ms(500);



   int cycles8, cycles;
   int32 freq;
   long freqc_high;
   long freqc_low;
   
     // below is for adc/voltage
   int16 adc_value;
   float volts,lux;
   setup_adc_ports(AN0);     
   setup_adc(ADC_CLOCK_DIV_64);   //  setup_adc(ADC_CLOCK_DIV_8);    - zashtoto cpu e 20mhz  i protheus dava greshka za TAd time 1.6us
   set_adc_channel(0);
   delay_us(20);   //you need this before the first reading
   adc_value = read_adc();

// end of code for adc
 
   while (TRUE) {
      cycles8=0;
      cycles=0;
      freqc_high=0;
      t1_overflow=0;
      set_timer1(0);
      setup_timer_1(T1_EXTERNAL|T1_DIV_BY_1);
/* ___ wait one second ___  */

      while (cycles!=0xFF) { //true=3, false=4
       cycles8=0; //1 cycle
       //start inner loop
       while (cycles8!=0xFF) { //true=3, false=4
         if (t1_overflow)//true=2,false=3             //----|
            {t1_overflow=0;freqc_high++;}//6 cycles   //    |
         else                                         //    |-- 8 cycles
            {delay_cycles(5);}                        //----|
         delay_cycles(62); //x
         cycles8++; //1
 ///2 cycles to jump to top
 //math: end inner loop
 //math: total inner loop=((3+8+x+1+2)*255 + 4)*255
 //math: if x=62.87781 then inner loops takes 5mil instructions
 //math: if x=62 then inner loop takes 4942920, have to fill 57080 cycles
  }
 delay_cycles(216);      //y
 cycles++;          ///1 cycle
 ///2 cylces to jump to top
 //math: outer=(3+1+y+1+2)*255+4=57080
 //math: y=(57080-4)/255)-(3+1+0+0+1+2)
 //math: if y=216.827450980392156862745098039216 then outer loop cylces is 57080
 //math: if y=216 then outer loop cycles is off by 211 cycles.  z=211
}
      delay_cycles(211);   //z
/* ___ end waiting 1 second ___ */
      setup_timer_1(T1_DISABLED);   //turn of counter to prevent corruption while grabbing value
      if (t1_overflow)            //check one last time for overflow
          freqc_high++;
      freqc_low=get_timer1();      //get timer1 value as the least sign. 16bits of freq counter
      freq=make32(freqc_high,freqc_low);   //use new make32 function to join lsb and msb


    volts = (float)(adc_value * 5)/1023.0; // adc to voltage conversion
     lux=(float)(volts*1333); // to be calibrated for measuring lux with photodiode
   
       
         lcd_gotoxy(1,1);
         printf(lcd_putc,"%LU Hz\r\n",freq);      //and print frequency
          lcd_gotoxy(1,2);
    printf(lcd_putc, "%3.3f", volts);
     lcd_gotoxy(1,3);
      printf(lcd_putc,"%4.2f",lux);
         delay_ms(1000);
   
   
   }
}


Here is the Proteus design. I thought it is missing a battery for voltage generator for input of RA0. I have a voltage source connected to RA0 in the simulation http://img441.imageshack.us/img441/3352/frequencycounter.png

Should i be worried for the errors above and will there be a problem with the cpu overload if i try to measure frequency like 10-30 khz ? What is the maximum frequency this code can measure ?
tcruise7771



Joined: 12 Apr 2013
Posts: 24

View user's profile Send private message

PostPosted: Fri Apr 12, 2013 8:08 am     Reply with quote

I have fixed the warnings by grounding the R/W and disabling it in the FLEXLCD . Seems to be stable and from what i read the cpu warning is due to my computer limitations for proteus simulation and not the pic controller speed itself
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Fri Apr 12, 2013 11:24 am     Reply with quote

http://www.ccsinfo.com/forum/viewtopic.php?t=47549

this is a ccs forum - not Isis , which does not work reliably with ccs , let alone the real world.
tcruise7771



Joined: 12 Apr 2013
Posts: 24

View user's profile Send private message

PostPosted: Sat Apr 13, 2013 12:43 am     Reply with quote

Sorry about Proteus related questions i am new to this forum, will read the forum rules.
I was asking about the code, i gave the link for the schematic only as a reference. I couldn't understand why if i have the R/W set to RB1 there is confusion. I think it tried to both read and write and that leads to the " Logic Connection(s) detected on net#x. What am i missing in my source code ?
temtronic



Joined: 01 Jul 2010
Posts: 9174
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sat Apr 13, 2013 5:39 am     Reply with quote

general comments...
1) work with real hardware. No one here has the time or interest in rewriting the Isis/ proteus software. It's just too buggy, faulty drcs, errors.

2)Simplify! Get rid of all code NOT needed for 'frequency' portion of your project.

3) CCS C likes all variables before any 'real code'(main). You init the LCD, then declare some variables inside main. Put them before 'main'.

4) Always add 'errors' to the uses rs232(...options...) when using the hardware UART. It'll keep the PIC from stopping due to 'overrun' condition.

5) look through the examples that CCS supplies in, of all places, the 'examples' folder. You should find 2 or 3 examples that deal with 'frequency' programs.

6) learn to use 'search' on this forum. You'll find several topics, similar to yours. Also check the 'code library'. Use keyword 'tachometer' might find similar program.

7) When using LCD modules, I always follow this sequence...
powerup PIC...
delay_ms(1000);
lcd_init();
delay_ms(500);
...
main()

Not all LCD modules are the same, different timings, even if they are 'compatible'.
The 1 second delay allows the LCD hardware to 'get organised'
The 1/2 second delay makes sure it is 'ready for work'.

hth
jay
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