CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

using power control module in pic 18F2431

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
hunterdd



Joined: 29 Mar 2014
Posts: 6

View user's profile Send private message

using power control module in pic 18F2431
PostPosted: Sat Mar 29, 2014 11:03 am     Reply with quote

hi everybody Smile
I was wondering if anbody had used this module and if possible he can provide me with an exemple written in C to use it.
Actually I came to make it work (pwm0 activated and pwm2 is deactivated), but when I try to invert (pwm2 activated and pwm0 deactivated) it doesn't work and I don't know why??!!
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Mar 29, 2014 1:20 pm     Reply with quote

Post your working program and your non-working program.
The programs should be short and they should compile with no errors.

Also post your CCS compiler version. It's a number in this format:
4.xxx or 5.xxx and you will find it at the top of the .LST file, which will
be in your project directory after a successful compilation.

Examples of short but complete Power PWM programs:
http://www.ccsinfo.com/forum/viewtopic.php?t=48851&start=1
http://www.ccsinfo.com/forum/viewtopic.php?t=37206&start=2
hunterdd



Joined: 29 Mar 2014
Posts: 6

View user's profile Send private message

PostPosted: Wed Apr 02, 2014 4:08 am     Reply with quote

The version of my compiler is 4.140 and here's my test program :
Code:

#include <18F2431.h>
 
#use delay(clock=20000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)
 
set_tris_b(ALL_out);
int16 pos;
#define POWER_PWM_PERIOD 999  // 1 KHz pwm freq with 8 MHz osc.
 
#int_IC3DR
void  IC3DR_isr(void)
{
}

#int_IC2QEI
void  IC2QEI_isr(void)
{
}

void avance()
{
setup_power_pwm_pins(PWM_ODD_ON,PWM_OFF,PWM_OFF,PWM_OFF);
set_power_pwm0_duty(100);
set_power_pwm2_duty(0);
}

void recul()
{
setup_power_pwm_pins(PWM_ODD_ON,PWM_ODD_ON,PWM_OFF,PWM_OFF);
set_power_pwm0_duty(0);
set_power_pwm2_duty(100);
}

void PID(int x)
{

}

void main()
{
setup_timer_5(T5_INTERNAL | T5_DIV_BY_4);

enable_interrupts(INT_IC3DR);
enable_interrupts(INT_IC2QEI);
enable_interrupts(GLOBAL);
   
// Setup the 4 Power PWM channels as ordinary pwm channels.
setup_qei(QEI_MODE_X4_RESET_ON_MATCH | QEI_VELOCITY_MODE_ENABLED | QEI_VELOCITY_PULSE_DIV_4 ,QEI_FILTER_ENABLE_QEB | QEI_FILTER_ENABLE_QEA,50000);
   
setup_power_pwm(PWM_FREE_RUN, 1, 0, POWER_PWM_PERIOD, 0, 1,50);

while(TRUE)
   {
     pos=qei_get_count(QEI_GET_POSITION_COUNT);
     output_low(PIN_C0);
     avance();
         
     if (pos>16)
        {
          delay_ms(50);
          recul();
        }
    }
}

The main problem is in the "recul()" fonction ??!!
hunterdd



Joined: 29 Mar 2014
Posts: 6

View user's profile Send private message

PostPosted: Mon Apr 07, 2014 4:12 pm     Reply with quote

any suggestion ??
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Apr 07, 2014 4:44 pm     Reply with quote

Quote:
#include <18F2431.h>

#use delay(clock=20000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)

set_tris_b(ALL_out);
int16 pos;

Where are your #fuses ? They're missing. Is this Proteus ? Proteus
doesn't care about fuses. That suggests it is actually Proteus.

2nd thing. You have a CCS function (set_tris_b) just stuck out in space.
It won't do anything there. Functions have to be within main() or some
other function.
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Mon Apr 07, 2014 6:05 pm     Reply with quote

what is the thinking behind your two ISR servicing routines ?

as is,
there is "no there , there "

Very Happy Very Happy Very Happy
hunterdd



Joined: 29 Mar 2014
Posts: 6

View user's profile Send private message

PostPosted: Mon Apr 07, 2014 11:57 pm     Reply with quote

thank's for replying Smile
first of all for the fuses they are included in the .h file so no need to do the same work over and over
2nd for the set_trib_b() yes it's a mistake but even with that my program work as expected exept the handeling of the pwm module that i cant come to correctly configurate it !! :(

for the other answer ISR() fonctions here are not needed in this phase !!!
i just want to make the pwm work correctly and then i will see the other features of the algorithm ;)
hunterdd



Joined: 29 Mar 2014
Posts: 6

View user's profile Send private message

PostPosted: Tue Apr 08, 2014 12:05 am     Reply with quote

So the main problem is that i can't shutdown pwm0 and make only pwm2 work because this combination is not supported with this compiler and i don't know why and even if set the duty cycle of pwm0 to have it shut!!! It does give an output signal instead:

setup_power_pwm_pins(PWM_OFF,PWM_BOTH_ON,PWM_OFF,PWM_OFF);
Ttelmah



Joined: 11 Mar 2010
Posts: 19346

View user's profile Send private message

PostPosted: Tue Apr 08, 2014 12:45 am     Reply with quote

Don't blame the compiler.

Always start by reading the data sheet. Is what you want to do supported by the chip?.
Code:

111 =All odd PWM I/O pins enabled for PWM output.
110 =PWM1, PWM3 pins enabled for PWM output.
101 =All PWM I/O pins enabled for PWM output.
100 =PWM0, PWM1, PWM2, PWM3, PWM4 and PWM5 pins enabled for PWM output.
011 =PWM0, PWM1, PWM2 and PWM3 I/O pins enabled for PWM output.
010 =PWM0 and PWM1 pins enabled for PWM output.
001 =PWM1 pin is enabled for PWM output.
000 =PWM module disabled. All PWM I/O pins are general purpose I/O.

PWMCON0 register settings for the chip.

As you can see if you look at the list there is no option that enables PWM2 and not PWM0.

Always start with what the chip can do. The compiler can't do anything the chip can't.

What you can do, is use the 'output override' ability to turn off output 0.

set_power_pwm_override(0,TRUE,0);

Will disable the PWM0 output.
hunterdd



Joined: 29 Mar 2014
Posts: 6

View user's profile Send private message

PostPosted: Thu Apr 10, 2014 3:17 am     Reply with quote

Thanks Ttelmah Smile I actually managed to do what i want using the duty cycle of the PWM as my weapon 3Smile
But still the overide function would be better in this case as you suggested ;)
thanks to your answer i knew how to use it correctly :D
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Thu Apr 10, 2014 5:24 am     Reply with quote

hunterdd wrote:
first of all for the fuses they are included in the .h file so no need to do the same work over and over
Ehhh...
You modified the original CCS supplied header file to be efficient???

This is bad practice!
Have you considered what will happen on installing the next compiler update?
What will happen when you start a 2nd project that requires other fuse settings?
What will happen when you hand your project to someone else?

Please keep all project specific settings inside your project directory. Don't modify the original compiler supplied files.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group