Jump to content
Sign in to follow this  
Haluk

#define Fn(x)

Recommended Posts

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}

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

Your content will need to be approved by a moderator

Guest
You are commenting as a guest. If you have an account, please sign in.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×