caramoan tour package

caramoan tour package

Author Topic: Q&A sa CCS C  (Read 7202 times)

Offline zer0w1ng

  • Technical People
  • Gas Turbine
  • *****
  • Posts: 2179
  • Pogi/Ganda Points: 305
  • Gender: Male
  • Enter any 11-digit prime number to continue...
    • The Cebuano Geek
Re: Q&A sa CCS C
« Reply #20 on: February 27, 2009, 04:54:09 PM »
di ko alam...
hehehe
ilang time ba ang required para madaya ang mata sa mga multiplexed seven segment (in your case, tatlo yan)...? hehehe ;D

50Hz minimum is enough for persistence of vision to work properly.  That is why our power AC cycle frequency is 60Hz and europe uses 50Hz.

So T = 1/50Hz = 20ms is required for 1 light to be seen as ON all the time.
For 3 lights this will be 1/50/3 = 6.67 ms.
The Cebuano Geek

Philippine Electronics Forum

Re: Q&A sa CCS C
« Reply #20 on: February 27, 2009, 04:54:09 PM »

Offline clarkent

  • Lead Acid Battery
  • *******
  • Posts: 505
  • Pogi/Ganda Points: 20
  • Gender: Male
  • iehs
Re: Q&A sa CCS C
« Reply #21 on: February 27, 2009, 04:57:54 PM »
ah ganun pala yung.hehe thnx for the info sir zero.

sir zero,

ito po yung syntax sa pagwrite sa eeprom diba?

               write_eeprom(variable,address);

ano po kaya ang routine if i'm going to write 3 variables to 3 different addresses?

say ones, tens, hundred are count files and i want to save their contents to 3 different locations in the eeprom.
if you think you can or think you can't, you're probably right -h.ford

Philippine Electronics Forum

Re: Q&A sa CCS C
« Reply #21 on: February 27, 2009, 04:57:54 PM »

Offline clarkent

  • Lead Acid Battery
  • *******
  • Posts: 505
  • Pogi/Ganda Points: 20
  • Gender: Male
  • iehs
Re: Q&A sa CCS C
« Reply #22 on: February 27, 2009, 04:59:41 PM »
ano po pala ang pagkakaiba ng write_eeprom() sa write_program_eeprom()?
if you think you can or think you can't, you're probably right -h.ford

Philippine Electronics Forum

Re: Q&A sa CCS C
« Reply #22 on: February 27, 2009, 04:59:41 PM »

Offline marcelino

  • Moderator
  • Solar Power Satellite
  • *****
  • Posts: 6016
  • Pogi/Ganda Points: 258
  • ...keep moving forward! - Robinson's
Re: Q&A sa CCS C
« Reply #23 on: February 27, 2009, 05:01:51 PM »
50Hz minimum is enough for persistence of vision to work properly.  That is why our power AC cycle frequency is 60Hz and europe uses 50Hz.

So T = 1/50Hz = 20ms is required for 1 light to be seen as ON all the time.
For 3 lights this will be 1/50/3 = 6.67 ms.


paano po yan sir, sobrang bilis pala... heheh ;D

e ang lowest possible TMRO overflow is 31.2ms?

dapat pala po baguhin ang structure nung program. Di pupwede yung example ko?
"Don't take life seriously. After all, no one has ever come out of it alive. -Bugs Bunny"

Philippine Electronics Forum

Re: Q&A sa CCS C
« Reply #23 on: February 27, 2009, 05:01:51 PM »

Offline marcelino

  • Moderator
  • Solar Power Satellite
  • *****
  • Posts: 6016
  • Pogi/Ganda Points: 258
  • ...keep moving forward! - Robinson's
Re: Q&A sa CCS C
« Reply #24 on: February 27, 2009, 05:03:18 PM »
ano po pala ang pagkakaiba ng write_eeprom() sa write_program_eeprom()?

check mo yung help... diniscuss ang pagkakaiba...
"Don't take life seriously. After all, no one has ever come out of it alive. -Bugs Bunny"

Philippine Electronics Forum

Re: Q&A sa CCS C
« Reply #24 on: February 27, 2009, 05:03:18 PM »

Offline zer0w1ng

  • Technical People
  • Gas Turbine
  • *****
  • Posts: 2179
  • Pogi/Ganda Points: 305
  • Gender: Male
  • Enter any 11-digit prime number to continue...
    • The Cebuano Geek
Re: Q&A sa CCS C
« Reply #25 on: February 27, 2009, 05:17:29 PM »
paano po yan sir, sobrang bilis pala... heheh ;D

e ang lowest possible TMRO overflow is 31.2ms?

dapat pala po baguhin ang structure nung program. Di pupwede yung example ko?

The prescaler value for TMR0 should be lowered.
TMR0 can be set to overflow minimum 256usec on 4MHz crystal.
This is without prescaler. 

For the application a prescaler of 16 is advisable.
T = Prescaler * 256 /(Fosc/4) = 16 * 256 / (4000000/4) = 4ms.
This is chosen to be a bit lower than 6.67ms required to work.
The Cebuano Geek

Offline marcelino

  • Moderator
  • Solar Power Satellite
  • *****
  • Posts: 6016
  • Pogi/Ganda Points: 258
  • ...keep moving forward! - Robinson's
Re: Q&A sa CCS C
« Reply #26 on: February 27, 2009, 05:29:31 PM »
The prescaler value for TMR0 should be lowered.
TMR0 can be set to overflow minimum 256usec on 4MHz crystal.
This is without prescaler. 

For the application a prescaler of 16 is advisable.
T = Prescaler * 256 /(Fosc/4) = 16 * 256 / (4000000/4) = 4ms.
This is chosen to be a bit lower than 6.67ms required to work.

thank you sir for such information...
though wala pa akong pag-gagamitan in the mean time, this will be very helpful in the future.

hanggang ngayon di ko pa din namamaster tong mga setups for timerX (prescalers thingy).
Another good reason to migrate to hitech c. ;D


SO, kent, use 4Mhz para ok na... heheh ;D

change mo lang yung
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_32);
to
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_16);
"Don't take life seriously. After all, no one has ever come out of it alive. -Bugs Bunny"

Offline marcelino

  • Moderator
  • Solar Power Satellite
  • *****
  • Posts: 6016
  • Pogi/Ganda Points: 258
  • ...keep moving forward! - Robinson's
Re: Q&A sa CCS C
« Reply #27 on: February 27, 2009, 05:33:04 PM »
Sir Zero, kung marami pa po palang processes kapag na reach ang 10mins in clarkent's application, dapat babaan pa, di ba?
say prescaler of 8 na so that 2ms na ang overflow...
"Don't take life seriously. After all, no one has ever come out of it alive. -Bugs Bunny"

Offline zer0w1ng

  • Technical People
  • Gas Turbine
  • *****
  • Posts: 2179
  • Pogi/Ganda Points: 305
  • Gender: Male
  • Enter any 11-digit prime number to continue...
    • The Cebuano Geek
Re: Q&A sa CCS C
« Reply #28 on: February 27, 2009, 06:02:19 PM »
Sir Zero, kung marami pa po palang processes kapag na reach ang 10mins in clarkent's application, dapat babaan pa, di ba?
say prescaler of 8 na so that 2ms na ang overflow...

10 minutes is already very long in the MCU's point of view (600 million instructions) so irregardless of the number of tasks this still ok.  The only thing needed is to modify the ISR function to not to set the flag too often by adding delay counters for this application to compensate for the faster TMR0 overflow interrupts.

Like this:
Code: [Select]

#define TMR0_SOFTWARE_DIVIDER  (1000000UL/4096)

void  RTCC_isr(void)
{
   static delay_counter = 0;

   ++delay_counter;

   if (delay_counter > TMR0_SOFTWARE_DIVIDER)
   {
      delay_counter = 0;
      RTCC_flag = TRUE;          //fires when RTCC interrupt occurs
   }

   LED_matrix_scan_function();

}
The Cebuano Geek

Offline marcelino

  • Moderator
  • Solar Power Satellite
  • *****
  • Posts: 6016
  • Pogi/Ganda Points: 258
  • ...keep moving forward! - Robinson's
Re: Q&A sa CCS C
« Reply #29 on: February 27, 2009, 06:14:34 PM »
I see... so for this application, mas mabuti pa kung yung delay counter ay nasa loob na ng ISR para kahit may min = 10 na, patuloy pa din ang counting. required kasi ni clarkent ay every 10 mins po daw magsesave sa eeprom.
at nasa loob na din po pala ang refresh ng seven segment....

I once read that lot of process inside an ISR is not advisable, but now i realized it would still depend on a particular application.

maraming-maraming salamat sir. :)

pogi mo!
"Don't take life seriously. After all, no one has ever come out of it alive. -Bugs Bunny"

Offline zer0w1ng

  • Technical People
  • Gas Turbine
  • *****
  • Posts: 2179
  • Pogi/Ganda Points: 305
  • Gender: Male
  • Enter any 11-digit prime number to continue...
    • The Cebuano Geek
Re: Q&A sa CCS C
« Reply #30 on: February 27, 2009, 06:21:27 PM »
I once read that lot of process inside an ISR is not advisable, but now i realized it would still depend on a particular application.

maraming-maraming salamat sir. :)

pogi mo!

Yes too much code is not advisable if inside the ISR.

But in this case the LED refresh is just setting I/O PORT with values, 7segment map if direct or just binary number if with a decoder. Plus updating the scan lines.  This is not big and could be placed inside the ISR. 

This way the display scanning runs in the background and one just sets the display buffer the value to be displayed.

Thanks for the point. ;D
The Cebuano Geek

Offline clarkent

  • Lead Acid Battery
  • *******
  • Posts: 505
  • Pogi/Ganda Points: 20
  • Gender: Male
  • iehs
Re: Q&A sa CCS C
« Reply #31 on: February 28, 2009, 10:55:35 AM »
10 minutes is already very long in the MCU's point of view (600 million instructions) so irregardless of the number of tasks this still ok.  The only thing needed is to modify the ISR function to not to set the flag too often by adding delay counters for this application to compensate for the faster TMR0 overflow interrupts.

Like this:
Code: [Select]

#define TMR0_SOFTWARE_DIVIDER  (1000000UL/4096)

void  RTCC_isr(void)
{
   static delay_counter = 0;

   ++delay_counter;

   if (delay_counter > TMR0_SOFTWARE_DIVIDER)
   {
      delay_counter = 0;
      RTCC_flag = TRUE;          //fires when RTCC interrupt occurs
   }

   LED_matrix_scan_function();

}


sir zero medyo nosebleed po ako sa code na to, diko pa naman talaga kasi kabisado ang ccsc e. ano po ang purpose ng line na to:


#define TMR0_SOFTWARE_DIVIDER  (1000000UL/4096)
if you think you can or think you can't, you're probably right -h.ford

Offline clarkent

  • Lead Acid Battery
  • *******
  • Posts: 505
  • Pogi/Ganda Points: 20
  • Gender: Male
  • iehs
Re: Q&A sa CCS C
« Reply #32 on: February 28, 2009, 11:09:38 AM »
Code: [Select]
#include <16F84A.h>

#FUSES NOWDT,[color=red]LP[/color],NOPUT,NOPROTECT

#use delay(clock=32768)
#byte porta = 5
#byte portb = 6
       
short RTCC_flag;
int ones, tens, huns;

#int_RTCC
void  RTCC_isr(void)
{
   RTCC_flag = TRUE;          //fires when RTCC interrupt occurs
}

void main()
{
   int sec, min;
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_128);    //overflow every 1.0s
   enable_interrupts(INT_RTCC);
   enable_interrupts(GLOBAL);
   set_tris_a(0x00);
   set_tris_b(0x00);
   
   ones = 0x03;
   tens =  0x02;
   huns = 0x01;
   
   while(TRUE)
   {
      if(RTCC_flag)
      {
         RTCC_flag = FALSE;
         sec++;
       }
         if(sec>=15)
         {
            sec = 0;
            min++;
          }
            if(min>=10)
            {
               min = 0;
               disable_interrupts(GLOBAL);
               write_eeprom(ones,0x00);
               write_eeprom(tens,0x01);
               write_eeprom(huns,0x02);
               enable_interrupts(GLOBAL);
            }
           
              porta = ones;
              portb = 0x01;
              porta = tens;
              portb = 0x02;
              porta = huns;
              portb = 0x04;
   }
}

kagabi po natry ko ang code sa proteus, nakapaggenerate ako ng 9 mins and 57 sec bago nakapunta sa write eeprom, pero diko po alam kung yung routine para sa pagwrite ay gumana. yung una ko po kasing try nyan LEDs lang sa ra1 and ra0. ra0 muna yung nakailaw then after 9mins and 57secs yung led naman sa ra1 yung umilaw. do you think that it would work kasama ang eeprom routine ko.?
if you think you can or think you can't, you're probably right -h.ford

Offline clarkent

  • Lead Acid Battery
  • *******
  • Posts: 505
  • Pogi/Ganda Points: 20
  • Gender: Male
  • iehs
Re: Q&A sa CCS C
« Reply #33 on: February 28, 2009, 11:40:19 AM »
correction:



 setup_timer_0(RTCC_INTERNAL|RTCC_DIV_128);    //overflow every 1.0s


should be

 setup_timer_0(RTCC_INTERNAL|RTCC_DIV_128);    //overflow every 4.0s
if you think you can or think you can't, you're probably right -h.ford

Offline marcelino

  • Moderator
  • Solar Power Satellite
  • *****
  • Posts: 6016
  • Pogi/Ganda Points: 258
  • ...keep moving forward! - Robinson's
Re: Q&A sa CCS C
« Reply #34 on: February 28, 2009, 12:53:50 PM »
#define TMR0_SOFTWARE_DIVIDER  (1000000UL/4096)

definition lang naman to ng content ng TMR0_SOFTWARE_DIVIDER

di ba at 4Mhz oscillator, then as suggested by sir zero, we set the prescaler sa 16 so that overflow occurs every 4ms. kasi gusto nating dayain ang 6ms for the refreshing ng multiplexed seven segment. So every 4ms, magkakaroon ng overflow tapos mag-iincrement ang delay_counter. kapag na reach nya yung value ng TMR0_SOFTWARE_DIVIDER , saka lang ang RTCC_isr maybibigay ng RTCC_flag=true. Sa tingin ko, you can assign any values on that definition para di magfire ang flag nag ISR every 4ms.

I can see you still insisted of making use of 32768 ha...  may magiging issue ka sa pagdaya ng multiplex seven segment mo kung magkakacount ang counter mo every 4s. As stated by sir zero, it should be below 6.67ms
50Hz minimum is enough for persistence of vision to work properly.  That is why our power AC cycle frequency is 60Hz and europe uses 50Hz.

So T = 1/50Hz = 20ms is required for 1 light to be seen as ON all the time.
For 3 lights this will be 1/50/3 = 6.67 ms.

"Don't take life seriously. After all, no one has ever come out of it alive. -Bugs Bunny"

Offline marcelino

  • Moderator
  • Solar Power Satellite
  • *****
  • Posts: 6016
  • Pogi/Ganda Points: 258
  • ...keep moving forward! - Robinson's
Re: Q&A sa CCS C
« Reply #35 on: February 28, 2009, 02:02:51 PM »
Kent,

i suggest to do the code this way....

Code: [Select]
#include <16F84A.h>

#FUSES NOWDT,HS,NOPUT,NOPROTECT

#define count_TIME 10         //in minutes

short RTCC_flag;
int sec,min;

#int_RTCC
void  RTCC_isr(void)
{
   sec++;
   if (sec>=60)
   {
      sec=0;
      min++;
      if(min>=count_TIME)
      {
         min =0;
         RTCC_flag = TRUE;
      }
   }
   //... multiplexed seven segment rountine here.
}

void main()
{
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_16);    //overflow every 4ms
   enable_interrupts(INT_RTCC);
   enable_interrupts(GLOBAL);
   
   while(TRUE)
   {
      if(RTCC_flag)
      {
         RTCC_flag = FALSE;
         //..... do the EEPROM THINGY HERE.
      }   
   }
}
"Don't take life seriously. After all, no one has ever come out of it alive. -Bugs Bunny"

Offline clarkent

  • Lead Acid Battery
  • *******
  • Posts: 505
  • Pogi/Ganda Points: 20
  • Gender: Male
  • iehs
Re: Q&A sa CCS C
« Reply #36 on: February 28, 2009, 02:57:27 PM »
Kent,

i suggest to do the code this way....

Code: [Select]
#include <16F84A.h>

#FUSES NOWDT,HS,NOPUT,NOPROTECT

#define count_TIME 10         //in minutes

short RTCC_flag;
int sec,min;

#int_RTCC
void  RTCC_isr(void)
{
   sec++;
   if (sec>=60)
   {
      sec=0;
      min++;
      if(min>=count_TIME)
      {
         min =0;
         RTCC_flag = TRUE;
      }
   }
   //... multiplexed seven segment rountine here.
}

void main()
{
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_16);    //overflow every 4ms
   enable_interrupts(INT_RTCC);
   enable_interrupts(GLOBAL);
  
   while(TRUE)
   {
      if(RTCC_flag)
      {
         RTCC_flag = FALSE;
         //..... do the EEPROM THINGY HERE.
      }  
   }
}


WOW!

ang galing na suggested code mo sir marce, pogi mo!!!hehe

ang problem ko lang sir kasi wala akong 4Mhz na xtal e, pwede ko bang gamitin ang 32768 para makacreate ng 4ms sa tmr0?hehe try ko ngang magcompute.
if you think you can or think you can't, you're probably right -h.ford

Offline marcelino

  • Moderator
  • Solar Power Satellite
  • *****
  • Posts: 6016
  • Pogi/Ganda Points: 258
  • ...keep moving forward! - Robinson's
Re: Q&A sa CCS C
« Reply #37 on: February 28, 2009, 03:35:28 PM »
^ngex!!!

malabo... lowest possible for 32768Hz is 32.1ms

mali nga yung gawa ko... heheh ;D
"Don't take life seriously. After all, no one has ever come out of it alive. -Bugs Bunny"

Offline marcelino

  • Moderator
  • Solar Power Satellite
  • *****
  • Posts: 6016
  • Pogi/Ganda Points: 258
  • ...keep moving forward! - Robinson's
Re: Q&A sa CCS C
« Reply #38 on: February 28, 2009, 03:42:10 PM »
dapat pala ganito:

Code: [Select]
short RTCC_flag;
int msec4ms,sec,min;   

#int_RTCC
void  RTCC_isr(void)
{
   msec4ms++;        //increment every 4ms
                     // 1 sec  = 25*4ms
   if(msec>=25)               
   {
      msec = 0;
      sec++;
      if (sec>=60)
      {
         sec=0;
         min++;
         if(min>=count_TIME)
         {
            min =0;
            RTCC_flag = TRUE;
         }
      }
   }
   //... multiplexed seven segment rountine here.
}
"Don't take life seriously. After all, no one has ever come out of it alive. -Bugs Bunny"

Offline clarkent

  • Lead Acid Battery
  • *******
  • Posts: 505
  • Pogi/Ganda Points: 20
  • Gender: Male
  • iehs
Re: Q&A sa CCS C
« Reply #39 on: February 28, 2009, 03:43:57 PM »
isa pa nga palang problem na nakikita ko sa code ay gagamit ako ng LDR for up count and down count. parang mahirap ata syang ilagay sa code sa ginawa mo sir marce.

pwede po ba to:

          if(!input(pin_b7)){
                   while(!input(pin_b7))
                        { ; }                     //di ako cgurado kung pwede ang statement na to.
                   ones++;
           }
                else if(!input(pin_b6)){
                      while(!input(pin_b6))
                        { ; }                     //di ako cgurado kung pwede ang statement na to.
                   ones--;
                 }

pwede po kaya ang code na to?

nakapull-up po kasi ang rb7 and rb6, pag po nakadetect ang LDR at naglow ang rb7 aantayin nyang maghigh ulit ito bago nya iincrement ang ones. same thing sa rb6.
if you think you can or think you can't, you're probably right -h.ford

Philippine Electronics Forum

Re: Q&A sa CCS C
« Reply #39 on: February 28, 2009, 03:43:57 PM »

 

Privacy Policy

Contact Us: elabph@yahoo.com