I have a pb with my .c

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 2 and 3.

Moderators: Benj, Mods

Post Reply
WalkOver
Posts: 65
Joined: Fri Nov 23, 2007 11:24 pm

I have a pb with my .c

Post by WalkOver »

Hello to all Flowcode users !

I have a problem with my .c when I use a pwm macro. Please, look what I get:

Code: Select all

 //PWM0: //ImplΓ©mentations Macro


void FCD_PWM0_Enable(char nIdx)
{
	
	  //error checking
	  #ifndef MX_PWM
	    #warning "This chip does not have PWM capability"
	  #else
	    #ifndef MX_PWM_CNT
	      #pragma error FCD file error (no MX_PWM_CNT)
	    #endif
	    #if (MX_PWM_CNT < 1)
	      #pragma error FCD file error (MX_PWM_CNT < 1)
	    #endif
	    #if (MX_PWM_CNT > 2)
	      #pragma error FCD file error (MX_PWM_CNT > 2)
	    #endif
	    #ifndef MX_PWM_TRIS1
	      #pragma error FCD file error (no MX_PWM_TRIS1)
	    #endif
	    #ifndef MX_PWM_1
	      #pragma error FCD file error (no MX_PWM_1)
	    #endif
	    #if (MX_PWM_CNT == 2)
	      #ifndef MX_PWM_TRIS2
	        #pragma error FCD file error (no MX_PWM_TRIS2)
	      #endif
	      #ifndef MX_PWM_2
	        #pragma error FCD file error (no MX_PWM_2)
	      #endif
	    #endif
	    #if (0 == 1)
	      #ifndef MX_PWM_TRIS1a
	        #pragma error PWM component error (using alternative, but no MX_PWM_TRIS1a)
	        #define MX_PWM_ALT_ERROR
	      #endif
	      #ifndef MX_PWM_1a
	        #pragma error PWM component error (using alternative, but no MX_PWM_1a)
	        #define MX_PWM_ALT_ERROR
	      #endif
	    #endif
	    #if (0 == 2)
	      #ifndef MX_PWM_TRIS2a
	        #pragma error PWM component error (using alternative, but no MX_PWM_TRIS2a)
	        #define MX_PWM_ALT_ERROR
	      #endif
	      #ifndef MX_PWM_2a
	        #pragma error PWM component error (using alternative, but no MX_PWM_2a)
	        #define MX_PWM_ALT_ERROR
	      #endif
	    #endif
	  #endif

	 #ifdef MX_PWM
	    pr2 = 249;
	    t2con = 0x04;

	  #if (MX_PWM_CNT >= 1)
	    if (nIdx == 1)
	    {
	        ccp1con = 0x0C;

	      #if (0 == 1)
	       #ifndef MX_PWM_ALT_ERROR
	        clear_bit(MX_PWM_TRIS1a, MX_PWM_1a);
	       #endif
	      #else
	        clear_bit(MX_PWM_TRIS1, MX_PWM_1);
	      #endif
		}
	  #endif

	  #if (MX_PWM_CNT >= 2)
	    if (nIdx == 2)
	    {
	        ccp2con = 0x0C;
	      #if (0 == 2)
	       #ifndef MX_PWM_ALT_ERROR
	        clear_bit(MX_PWM_TRIS2a, MX_PWM_2a);
	       #endif
	      #else
	        clear_bit(MX_PWM_TRIS2, MX_PWM_2);
	      #endif
	   }
	  #endif
	 #endif

	 #ifdef MX_PWM_ALT_ERROR
	   #undef MX_PWM_ALT_ERROR
	 #endif

}

void FCD_PWM0_Disable(char nIdx)
{
	
	  //error checking
	  #ifndef MX_PWM
	    #warning "This chip does not have PWM capability"
	  #endif

	 #ifdef MX_PWM
	  #if (MX_PWM_CNT >= 1)
	    if (nIdx == 1)
	    {
	        ccp1con = 0x00;
	    }
	  #endif

	  #if (MX_PWM_CNT >= 2)
	    if (nIdx == 2)
	    {
	        ccp2con = 0x00;
	    }
	  #endif
	 #endif

}

void FCD_PWM0_SetDutyCycle(char nIdx, char nDuty)
{
	
	  //error checking
	  #ifndef MX_PWM
	    #warning "This chip does not have PWM capability"
	  #endif

	 #ifdef MX_PWM
	  #if (MX_PWM_CNT >= 1)
	    if (nIdx == 1)
	    {
	        ccpr1l = nDuty;
	    }
	  #endif

	  #if (MX_PWM_CNT >= 2)
	    if (nIdx == 2)
	    {
	        ccpr2l = nDuty;
	    }
	  #endif
	 #endif

}

void FCD_PWM0_ChangePeriod(char nPeriodVal, char nPrescalerVal)
{
	
	  //error checking
	  #ifndef MX_PWM
	    #warning "This chip does not have PWM capability"
	  #endif

	  #ifdef MX_PWM
	    pr2 = nPeriodVal;

	    switch (nPrescalerVal)
	    {
	        case 1:
	            t2con = 0x04;
	            break;

	        case 4:
	            t2con = 0x05;
	            break;

	        case 16:
	            t2con = 0x06;
	            break;
	    }
	  #endif

Yet I use a peak 18F2620 which can generate pwm.
I tried checking the box "use alternative pin" but it does not solve the problem.
How can I correct this?

Thanks in advance.

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Post by Benj »

Hello WalkOver

This C code is correct. The part at the top is simply to check that there is indeed a valid PWM pin. Have you tried compiling your code. DOes it compile and run correctly?

WalkOver
Posts: 65
Joined: Fri Nov 23, 2007 11:24 pm

Post by WalkOver »

Yes, compilation ends successfully, but the simulation with the software Proteus Isis and my .hex doesn't work. I don't have the equipment to check the proper functioning of the PIC yet, but I think that the problem must come from Proteus.

Thanks for your prompt response :wink:

PS : Sorry for ma bad english :evil:

Post Reply