caramoan tour package

caramoan tour package

Author Topic: Code Compression (tips and tricks)  (Read 15381 times)

Offline 'yus

  • Technical People
  • Nuclear Reactor
  • *****
  • Posts: 4251
  • Pogi/Ganda Points: 299
  • Gender: Male
  • hw -> fw -> sw
    • yus' projects
Re: Code Compression (tips and tricks)
« Reply #100 on: March 21, 2008, 02:20:04 PM »
from CCS help file:
Quote
#BIT
--------------------------------------------------------------------------------
Syntax:
 #bit  id = x.y

Elements:
 id is a valid C identifier,

x is a constant or a C variable,

y is a constant 0-7.
 
Purpose:
 A new C variable (one bit) is created and is placed in memory at byte x and bit y.  This is useful to gain access in C directly to a bit in the processors special function register map.  It may also be used to easily access a bit of a standard C variable.

Examples:
 #bit T0IF = 0xb.2
...             
T0IF = 0; // Clear Timer 0 interrupt flag

int result;

#bit result_odd = result.0

...

if (result_odd)
hindi ata pwedeng basta-basta lang mag-define ng bit variable ?  ???
kasi may dinefine akong global variable:
Code: [Select]
int flags;
#bit flag_settings=flags.0
and then may siningit akong code sa isang function:
Code: [Select]
if(flag_settings)
    {
        disable_interrupts(INT_EXT);
        scope_settings();
        enable_interrupts(INT_EXT);
    }
lagi syang pumapasok  dun sa if condition, e hindi ko naman ginagalaw yung bit na flag_settings..  :'(
join  - Philippine Electronics and Robotics Enthusiasts Club - www.philrobotics.com

Philippine Electronics Forum

Re: Code Compression (tips and tricks)
« Reply #100 on: March 21, 2008, 02:20:04 PM »

Offline 0b00000111

  • Technical People
  • Solar Power Satellite
  • *****
  • Posts: 6129
  • Pogi/Ganda Points: 398
  • There is no delight in owning anything unshared.
Re: Code Compression (tips and tricks)
« Reply #101 on: March 21, 2008, 02:46:37 PM »
sineset mo ba ang flag_settings to 0 ulit bago matapos mga statements sa loob ng if?
E-Gizmo Mechatronix Central: www.e-gizmo.com

Tel #: (63)(2) 536-3378
Globe +63915-973-7691
Smart +63921-779-0748

Location Map

YM: julie.egizmo  aka Born2BeWired  ;D

Philippine Electronics Forum

Re: Code Compression (tips and tricks)
« Reply #101 on: March 21, 2008, 02:46:37 PM »

Offline 'yus

  • Technical People
  • Nuclear Reactor
  • *****
  • Posts: 4251
  • Pogi/Ganda Points: 299
  • Gender: Male
  • hw -> fw -> sw
    • yus' projects
Re: Code Compression (tips and tricks)
« Reply #102 on: March 21, 2008, 02:53:45 PM »
sineset mo ba ang flag_settings to 0 ulit bago matapos mga statements sa loob ng if?
dun sa function na scope_settings(), first line nya:
Code: [Select]
flag_settings = false;
kasama na rin nga sa mga initializations ko yung line na yun,
para siguradong 0 ang value ng flag_settings..

hula ko, nagagalaw yung register/location nung bit, kaya dapat tama ang pag-define..
hula lang hehe..  ;D
join  - Philippine Electronics and Robotics Enthusiasts Club - www.philrobotics.com

Philippine Electronics Forum

Re: Code Compression (tips and tricks)
« Reply #102 on: March 21, 2008, 02:53:45 PM »

Offline 'yus

  • Technical People
  • Nuclear Reactor
  • *****
  • Posts: 4251
  • Pogi/Ganda Points: 299
  • Gender: Male
  • hw -> fw -> sw
    • yus' projects
Re: Code Compression (tips and tricks)
« Reply #103 on: March 21, 2008, 02:59:20 PM »
mas mabilis ba ang execution ng:
Code: [Select]
if (this_BIT) execute_this_functon();compared sa:
Code: [Select]
if (this_BYTE == certain_value) execute_this_function(); ???
join  - Philippine Electronics and Robotics Enthusiasts Club - www.philrobotics.com

Philippine Electronics Forum

Re: Code Compression (tips and tricks)
« Reply #103 on: March 21, 2008, 02:59:20 PM »

Offline 0b00000111

  • Technical People
  • Solar Power Satellite
  • *****
  • Posts: 6129
  • Pogi/Ganda Points: 398
  • There is no delight in owning anything unshared.
Re: Code Compression (tips and tricks)
« Reply #104 on: March 21, 2008, 03:04:08 PM »
sa interrupt mo ba sineset ang flagsettings sa 1? pwede pasilip ng interrupt routine mo? :)

o kaya para mas sigurado , iset mo sa 0 yung flagsettings bago ienable ulit ang interrupt.

Code: [Select]
if(flag_settings)
    {
        disable_interrupts(INT_EXT);
        scope_settings();
        flag_settings=0;
        enable_interrupts(INT_EXT);
    }
E-Gizmo Mechatronix Central: www.e-gizmo.com

Tel #: (63)(2) 536-3378
Globe +63915-973-7691
Smart +63921-779-0748

Location Map

YM: julie.egizmo  aka Born2BeWired  ;D

Philippine Electronics Forum

Re: Code Compression (tips and tricks)
« Reply #104 on: March 21, 2008, 03:04:08 PM »

Offline 'yus

  • Technical People
  • Nuclear Reactor
  • *****
  • Posts: 4251
  • Pogi/Ganda Points: 299
  • Gender: Male
  • hw -> fw -> sw
    • yus' projects
Re: Code Compression (tips and tricks)
« Reply #105 on: March 21, 2008, 03:05:53 PM »
ito lang yung interrupt routine ko:
Code: [Select]
#int_EXT
void EXT_isr()
{
   flag_settings = true;
}
join  - Philippine Electronics and Robotics Enthusiasts Club - www.philrobotics.com

Offline 0b00000111

  • Technical People
  • Solar Power Satellite
  • *****
  • Posts: 6129
  • Pogi/Ganda Points: 398
  • There is no delight in owning anything unshared.
Re: Code Compression (tips and tricks)
« Reply #106 on: March 21, 2008, 03:08:52 PM »
ito lang yung interrupt routine ko:
Code: [Select]
#int_EXT
void EXT_isr()
{
   flag_settings = true;
}

clear mo yung interrupt flag bago lumabas ng interrupt routine. anong interrupt ba yan? INT0?
E-Gizmo Mechatronix Central: www.e-gizmo.com

Tel #: (63)(2) 536-3378
Globe +63915-973-7691
Smart +63921-779-0748

Location Map

YM: julie.egizmo  aka Born2BeWired  ;D

Offline 0b00000111

  • Technical People
  • Solar Power Satellite
  • *****
  • Posts: 6129
  • Pogi/Ganda Points: 398
  • There is no delight in owning anything unshared.
Re: Code Compression (tips and tricks)
« Reply #107 on: March 21, 2008, 03:12:10 PM »
try mo na lang ito


#int_EXT
void EXT_isr()
{
clear_interrupt(INT_EXT);
flag_settings = true;
}


-- di ako nagamit ng CCS, kaya di ako sure kung clear interrupt nga ba ang gamit pang clear ng interrupt flag..heheh
E-Gizmo Mechatronix Central: www.e-gizmo.com

Tel #: (63)(2) 536-3378
Globe +63915-973-7691
Smart +63921-779-0748

Location Map

YM: julie.egizmo  aka Born2BeWired  ;D

Offline 'yus

  • Technical People
  • Nuclear Reactor
  • *****
  • Posts: 4251
  • Pogi/Ganda Points: 299
  • Gender: Male
  • hw -> fw -> sw
    • yus' projects
Re: Code Compression (tips and tricks)
« Reply #108 on: March 21, 2008, 03:14:11 PM »
Code: [Select]
if(flag_settings)
    {
        disable_interrupts(INT_EXT);
        scope_settings();
        flag_settings=0;
        enable_interrupts(INT_EXT);
    }
na-try ko na ito.. same pa rin..  :'(
join  - Philippine Electronics and Robotics Enthusiasts Club - www.philrobotics.com

Offline 'yus

  • Technical People
  • Nuclear Reactor
  • *****
  • Posts: 4251
  • Pogi/Ganda Points: 299
  • Gender: Male
  • hw -> fw -> sw
    • yus' projects
Re: Code Compression (tips and tricks)
« Reply #109 on: March 21, 2008, 03:18:23 PM »
.. anong interrupt ba yan? INT0?
external interrupt sya.. may nakakabit akong push button (saka pull-up resistor)  sa pin B0..

pero gumagana yung interrupt kapag int variable gamit ko, hindi bit variable..
join  - Philippine Electronics and Robotics Enthusiasts Club - www.philrobotics.com

Offline 0b00000111

  • Technical People
  • Solar Power Satellite
  • *****
  • Posts: 6129
  • Pogi/Ganda Points: 398
  • There is no delight in owning anything unshared.
Re: Code Compression (tips and tricks)
« Reply #110 on: March 21, 2008, 03:30:17 PM »
i see... hiwalay mo na lang siguro siya ng variable using volatile unsigned char type.
E-Gizmo Mechatronix Central: www.e-gizmo.com

Tel #: (63)(2) 536-3378
Globe +63915-973-7691
Smart +63921-779-0748

Location Map

YM: julie.egizmo  aka Born2BeWired  ;D

Offline 'yus

  • Technical People
  • Nuclear Reactor
  • *****
  • Posts: 4251
  • Pogi/Ganda Points: 299
  • Gender: Male
  • hw -> fw -> sw
    • yus' projects
Re: Code Compression (tips and tricks)
« Reply #111 on: March 21, 2008, 03:32:02 PM »
try mo na lang ito


#int_EXT
void EXT_isr()
{
clear_interrupt(INT_EXT);
flag_settings = true;
}


-- di ako nagamit ng CCS, kaya di ako sure kung clear interrupt nga ba ang gamit pang clear ng interrupt flag..heheh
na-try ko na rin 'to.. walang error, wala rin effect..  :'(

pag-tyagaan ko na lang muna yung if(BYTE) condition instead of if(BIT)..  :(
join  - Philippine Electronics and Robotics Enthusiasts Club - www.philrobotics.com

Offline 'yus

  • Technical People
  • Nuclear Reactor
  • *****
  • Posts: 4251
  • Pogi/Ganda Points: 299
  • Gender: Male
  • hw -> fw -> sw
    • yus' projects
Re: Code Compression (tips and tricks)
« Reply #112 on: March 23, 2008, 10:25:18 PM »
tinitignan niyo ba yung code listing kung ano pinaka-efficient at optimized?

merong Python for PIC... ;D
Python for PIC ?  ???
ito ba yung may pinaka-optimized na resulting HEX file ?  ???
join  - Philippine Electronics and Robotics Enthusiasts Club - www.philrobotics.com

Offline rdpzycho

  • Technical People
  • Solar Power Satellite
  • *****
  • Posts: 10766
  • Pogi/Ganda Points: 635
  • Gender: Male
  • Respect Begets Respect
    • rdpzycho
Re: Code Compression (tips and tricks)
« Reply #113 on: March 23, 2008, 10:48:48 PM »
hindi ako sure kung pinaka-optimized yun pero malamang mas maraming commercial compilers ngayon ang mas optimized...

Pyastra yung name ng project...

mas madali lang intidihin ang Python Language compare to C (equivalency 6 lines of C = 1 line of Python, same as Java)...
‎"Divide each difficulty into as many parts as is feasible and necessary to resolve it."
- Rene Descartes

"For every difficult problem there is always a simple answer and most of them are wrong."
- Clayton Paul

Offline rdpzycho

  • Technical People
  • Solar Power Satellite
  • *****
  • Posts: 10766
  • Pogi/Ganda Points: 635
  • Gender: Male
  • Respect Begets Respect
    • rdpzycho
Re: Code Compression (tips and tricks)
« Reply #114 on: March 23, 2008, 10:54:16 PM »
mas mabilis ba ang execution ng:
Code: [Select]
if (this_BIT) execute_this_functon();compared sa:
Code: [Select]
if (this_BYTE == certain_value) execute_this_function(); ???

hindi ko kabisado instruction set ng PIC at methods ng CCS...sa 8051 mas efficient yung una...

dun sa una check lang kung nakaset yung bit then jump...

dun sa pangalawa ang alam kong method, kunin yung certain_value lagay sa register, then subtract yung this_BYTE...test for 0 then jump...
‎"Divide each difficulty into as many parts as is feasible and necessary to resolve it."
- Rene Descartes

"For every difficult problem there is always a simple answer and most of them are wrong."
- Clayton Paul

Offline Mentor Lee

  • Size C Battery
  • *****
  • Posts: 193
  • Pogi/Ganda Points: 16
  • Gender: Male
  • "Call to Me and I will answer you.....
Re: Code Compression (tips and tricks)
« Reply #115 on: March 29, 2008, 01:55:24 PM »
>kapag nag-declare ba ako ng function tapos di ko naman nagamit,
>magko-consume ba sya ng memory?  ???
On smart compilers, this should be automatically removed. AFAIR, It is called dead code removal. I don't have extensive experience on CCS but on Hitech and GCC removes this.

>same as sa variables, kapag nag-define ba ako ng variable tapos di ko naman nagamit,
>magko-consume din ba sya ng space?  ???
No. Global RAM variables are not removed. The compiler does not know if you used the variable using a pointer. So this is not removed to be safe.

But dynamic variables defined inside the functions are re-used other functions on same level by using a dynamic stack space employed by these new compilers if the micro has no hardware stack.
CCS C does not compile unused functions.
Variables inside a function (local) are implemented using the compiler assigned stack ( the hardware stack of PIC is exclusive for its own use only - there is no user access). You may also use unions (if applicable to your app) to save RAM and instead of passing arrays, you pass a pointer. If your PIC has a hardware multiplier (PIC18FxxxX), the compiler utilizes it automatically so code is naturally compressed. It is worthy not to turn off all the compiler messages since they will help you optimize your code.
...and show you great and inscrutable things that you do not know "
--Hotline 333--

Offline 'yus

  • Technical People
  • Nuclear Reactor
  • *****
  • Posts: 4251
  • Pogi/Ganda Points: 299
  • Gender: Male
  • hw -> fw -> sw
    • yus' projects
Re: Code Compression (tips and tricks)
« Reply #116 on: March 29, 2008, 05:19:28 PM »
... You may also use unions (if applicable to your app) to save RAM and instead of passing arrays, you pass a pointer...
what are unions ???
join  - Philippine Electronics and Robotics Enthusiasts Club - www.philrobotics.com

Offline Mentor Lee

  • Size C Battery
  • *****
  • Posts: 193
  • Pogi/Ganda Points: 16
  • Gender: Male
  • "Call to Me and I will answer you.....
Re: Code Compression (tips and tricks)
« Reply #117 on: March 29, 2008, 06:34:44 PM »
Union allows you to define the same  area of memory to hold different types of variables.
Ex. ( I assume a data width recognize by CCS C ( ie long = 2 bytes))
Code: [Select]
union  {
 long  train;
 char  loByte;
 char hiByte;
 byte _loByte;
 byte _hiByte;} ex_union ;

Union allows you to store different types of data in the same location. In the union given above, if you will declare the variables separately, you need 6 bytes of RAM but the implementation of this union requires only 2 bytes.
You can just access them the way you access a structure.
Code: [Select]
/* somewhere in the beginning of the main */
 long x;

/* .........................*/
   ex_union.train = x;
   ex_union.loByte= 0x3f;
   ex_union.hiByte= 0;
   ex_union._hiByte = 45;
but of course , union has its application .it is mostly used in dynamic data exchange. Be careful in using unions. The example I have given above will totally change the value of the hi & lo bytes of the long variable train.
...and show you great and inscrutable things that you do not know "
--Hotline 333--

Offline 'yus

  • Technical People
  • Nuclear Reactor
  • *****
  • Posts: 4251
  • Pogi/Ganda Points: 299
  • Gender: Male
  • hw -> fw -> sw
    • yus' projects
Re: Code Compression (tips and tricks)
« Reply #118 on: March 29, 2008, 07:29:37 PM »
Union allows you to store different types of data in the same location...
tito,
di kaya magkalito-lito ang compiler nito, o kaya yung pic mismo magkamali-mali ang processing ?  ???
join  - Philippine Electronics and Robotics Enthusiasts Club - www.philrobotics.com

Offline Mentor Lee

  • Size C Battery
  • *****
  • Posts: 193
  • Pogi/Ganda Points: 16
  • Gender: Male
  • "Call to Me and I will answer you.....
Re: Code Compression (tips and tricks)
« Reply #119 on: March 29, 2008, 10:44:57 PM »
Code: [Select]
di kaya magkalito-lito ang compiler nito, o kaya yung pic mismo magkamali-mali ang processing ?  Huh ;D
hindi naman hijo, union is a standard C data type. Try it in CCS C or SDCC and they will not complain. They are designed to handle such complicated data structure. You can also put a structure inside a union. Pero depende pa rin sa MCU mo. Kung malaki naman ang RAM/ROM , why bother to save space? Once naman na nagkasya yung code mo sa chip - that's it! The important thing is that your project goal is achieved.  ;)
...and show you great and inscrutable things that you do not know "
--Hotline 333--

Philippine Electronics Forum

Re: Code Compression (tips and tricks)
« Reply #119 on: March 29, 2008, 10:44:57 PM »

 

Privacy Policy

Contact Us: elabph@yahoo.com