Haluk 0 Posted July 6, 2005 Report Share Posted July 6, 2005 IDEVersion: SourceBoost IDE v603 Compiler: BoostC, C2C-plus, C2C++ or P2C-plus) CompilerVersion: ??? TargetDevice: PIC16F628 OS: WinXP in BoostC #define fn(x) dont work properly in test.c ...::: // PIC16F628 ... #define ClockFrequency 4000000 #define Timer2PreScale 16 #define Period(Hz) ((ClockFrequency / (Hz * Timer2PreScale * 4)) - 1) #define DutyCycle(Hz) (ClockFrequency / (Hz * Timer2PreScale)) #define CharToBCD© ((c % 10) + (( c / 10 ) << 4)) //#define BCDToChar(bcd) () void PWMInit( /* unsigned short Frequency */ ) { t2con = 00000011b; //set_bit(t2con, T2CKPS1); //set_bit(t2con, T2CKPS0); pr2 = Period(300);//pr2=207; // 300Hz=207 ; 333Hz=186 ... // 207=69*3 ; 69,138,207 ... ccpr1l = 0; ccp1con = 00001100b; //set_bit(ccp1con, CCP1M3); set_bit(ccp1con, CCP1M2); //return; }; in test.asm ...::: PWMInit_00000 ; { PWMInit ; function begin MOVLW 0x03 MOVWF gbl_t2con MOVLW 0xFF BSF STATUS, RP0 MOVWF gbl_pr2 BCF STATUS, RP0 CLRF gbl_ccpr1l MOVLW 0x0C MOVWF gbl_ccp1con RETURN ; } PWMInit function end in .asm pr2=0xFF ; But pr2 set to be happen 0xCF (pr2=0xCF)(pr2=207) ... {Excuse My Poor English} Quote Link to post Share on other sites
Pavel 0 Posted July 6, 2005 Report Share Posted July 6, 2005 Can't reproduce this problem. On the code I tried function define works properly. Since you didn't provide full sources it's difficult to tell exactly what is wrong with your code: #include <system.h> char foo( char x ) { return x / 3; } #define fn(x) foo(x) void main() { char ch = fn( 27 ); while(1); } Regards, Pavel Quote Link to post Share on other sites
Haluk 0 Posted July 6, 2005 Author Report Share Posted July 6, 2005 pr2 = 0xFF ; // THIS FALSE (IN test.asm) pr2 = 0xCF ; // THIS TRUE ... Please ReTest test.c in below... but, this define work properly ::: #define Period2(Hz) ((62500 / Hz) - 1) {{{ in test.c ...::: #include <system.h> // PIC16F628 ... #define ClockFrequency 4000000 #define Timer2PreScale 16 #define Period(Hz) ((ClockFrequency / (Hz * Timer2PreScale * 4)) - 1) #define DutyCycle(Hz) (ClockFrequency / (Hz * Timer2PreScale)) void MyFn(void) { pr2 = Period(300);//pr2=207; // 300Hz=207; 333Hz=186 ... }; void main() { MyFn(); }; /* //// in test.asm //// MyFn_00000 ; { MyFn; function begin MOVLW 0xFF :P BSF STATUS, RP0 MOVWF gbl_pr2 RETURN ; } MyFn function end //////// */ }}} {Excuse My Poor English} Regards, Haluk. Quote Link to post Share on other sites
Pavel 0 Posted July 6, 2005 Report Share Posted July 6, 2005 Looks like a bug. Thanks for reporting Regards, Pavel Quote Link to post Share on other sites
Pavel 0 Posted July 7, 2005 Report Share Posted July 7, 2005 Looked into this issue more. This is not a bug. You faced the limitation of the compiler where it doesn't support 32 bit math yet. In the expression the 'ClockFrequency' is truncated to a 16 bit number and this gives the result that you see. We work on adding support of 32 bit math and when it's done expressions like this will produce "more correct" results. Regards, Pavel Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.