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 CCS Technical Support

help in writing in C language for a pic18f4331
Goto page Previous  1, 2, 3, 4  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
wewe



Joined: 17 Apr 2010
Posts: 31

View user's profile Send private message

PostPosted: Sun Apr 25, 2010 1:14 pm     Reply with quote

And by the way, the power pwm I need is a pwm with a 10Khz frequency and a duty cycle varying from 0% to 100% (it depends on the value of the analog to digital conversion, when the value of the conversion is maximal I want the duty cycle to be 100% and if the value of the conversion is 0 then I want the duty cycle to be 0%, so the duty cycle is not constant).
As for the dead time it doesn't really matter, let's say I need a deadtime of 0.5 us.
and i followed the manual instructions perfectly , i wonder why i am not getting any results in proteus , there's nothing on the output of pwms 0 and 1
wewe



Joined: 17 Apr 2010
Posts: 31

View user's profile Send private message

PostPosted: Mon Apr 26, 2010 10:00 am     Reply with quote

Come one !!! No one ever used a power pwm here ???
I followed the series of instructions in the manual but I got nothing, maybe one of you can help
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Apr 26, 2010 12:16 pm     Reply with quote

It's so easy to find out if we ever used it. Use the forum's search page.
http://www.ccsinfo.com/forum/search.php
Search for the name of a power pwm function:
Quote:
setup_power_pwm


Then, run a text search engine on the CCS compiler directories.
Search for:
Quote:
setup_power_pwm

It pops this file up immediately:
Quote:
c:\program files\picc\examples\ex_power_pwm.c


Then use Google. Search for this:
Quote:
+setup_power_pwm motor

You will get at least 200 hits.

In other words, learn how to search.
wewe



Joined: 17 Apr 2010
Posts: 31

View user's profile Send private message

PostPosted: Tue Apr 27, 2010 12:44 pm     Reply with quote

Not working.
It seems like this project is going to last forever.
How hard can generating a pwm with a dead time along with its complementary can be ?? Especially that this complementary is automatically generated by the pic.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Apr 27, 2010 12:57 pm     Reply with quote

You're running a simulator that a lot of us don't have. How do you know
that Proteus simulates the Power PWM module correctly ? You don't.
Test it in hardware.

1. Post a short test program that sets up the Power PWM module and
attempts to output the PWM signals to control your motor. The test
program should be very short, with just 4 lines of code in main().
The test program must be complete and it must compile without errors.
Example:
http://www.ccsinfo.com/forum/viewtopic.php?t=30061&start=7
Do something like that, except with only one line to setup the PWM duty,
or at least the minimum number of lines that are required by your design.

2. Test the program and explain in detail how it fails to work.
If it works perfectly except for the deadtime delay being too small,
then say so. Explain in detail how it fails.

3. Post your compiler version.

If you do those three things, I can probably make it work.
bkamen



Joined: 07 Jan 2004
Posts: 1615
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Tue Apr 27, 2010 7:55 pm     Reply with quote

PCM programmer wrote:
Quote:
how can you guys simulate your codes

I do it in hardware. I build a board, and write the program, and test it.


That's what I do to...

Or - I have a couple of microchip's demo boards where I might write code that's similar or close to what I want to see if it works yet.

wewe wrote:
Not working.
It seems like this project is going to last forever.
How hard can generating a pwm with a dead time along with its complementary can be ?? Especially that this complementary is automatically generated by the pic.


You really need a prototype of the PIC at a basic level to accept your code and maybe have at least test points (in case the actual design requires more) for you to monitor.

It shouldn't be hard at all. I'm skeptical of simulators to some degree.

-Ben
_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
wewe



Joined: 17 Apr 2010
Posts: 31

View user's profile Send private message

PostPosted: Wed Apr 28, 2010 10:49 am     Reply with quote

[quote="bkamen"]
PCM programmer wrote:
Quote:
how can you guys simulate your codes

I do it in hardware. I build a board, and write the program, and test it.


my friend have a programmer that he built himself , these programmers work for both 16f and 18f pics??
and is there anything that i need to do with my program on CCS to write it , do i need to create a link between mplab and ccs before compiling and using the output files or what ?

and by the way when i start a new program and choose to disable the master clear pin , i can at this time leave the pin or i should give it power?
bkamen



Joined: 07 Jan 2004
Posts: 1615
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Wed Apr 28, 2010 11:01 am     Reply with quote

Depending on the version of CCS (IDE vs. Command line) there's a program that needs to be run that installs CCS as a compiler tool for MPLAB.


Once that is done, you're good to go using MPLAB with PIC-C.


YOUR problem will most be that MPLAB is made to work with Microchip's programmer/debuggers.

At this point, you will need to externally use your programmer.

From that perspective, I don't see any advantage to MPLAB other than maybe it's simulator. You won't be able to use MPLAB's debug features which are fabulous.

For all practical purposes, you could use UltraEdit/Studio, PIC-C and your programmer software.

And really - PICkit3's are so cheap.

-Ben
_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
wewe



Joined: 17 Apr 2010
Posts: 31

View user's profile Send private message

PostPosted: Wed Apr 28, 2010 11:10 am     Reply with quote

bkamen wrote:
Depending on the version of CCS (IDE vs. Command line) there's a program that needs to be run that installs CCS as a compiler tool for MPLAB.


Once that is done, you're good to go using MPLAB with PIC-C.


YOUR problem will most be that MPLAB is made to work with Microchip's programmer/debuggers.

At this point, you will need to externally use your programmer.

From that perspective, I don't see any advantage to MPLAB other than maybe it's simulator. You won't be able to use MPLAB's debug features which are fabulous.

For all practical purposes, you could use UltraEdit/Studio, PIC-C and your programmer software.

And really - PICkit3's are so cheap.

-Ben


hehe , okay , so i can use this programmer .....
here in lebanon i cant find anything other than microchip , you cant find these stuff easily , that's why i asked .
anyway i installed this tool that integrates ccs into mplab , is there anything else tha i need to do or just compile my program from mplab and burn it on the pic
my friend use pickit (software) i don't know if it's pickit3 or pickit2
bkamen



Joined: 07 Jan 2004
Posts: 1615
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Wed Apr 28, 2010 11:12 am     Reply with quote

Nope. that should do it.

When you create a new project, under project, you select the "toolsuite" you want to use and CCS is one of them listed.

-Ben
_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
wewe



Joined: 17 Apr 2010
Posts: 31

View user's profile Send private message

PostPosted: Thu Apr 29, 2010 11:55 am     Reply with quote

PCM programmer wrote:
You're running a simulator that a lot of us don't have. How do you know
that Proteus simulates the Power PWM module correctly ? You don't.
Test it in hardware.

1. Post a short test program that sets up the Power PWM module and
attempts to output the PWM signals to control your motor. The test
program should be very short, with just 4 lines of code in main().
The test program must be complete and it must compile without errors.
Example:
http://www.ccsinfo.com/forum/viewtopic.php?t=30061&start=7
Do something like that, except with only one line to setup the PWM duty,
or at least the minimum number of lines that are required by your design.

2. Test the program and explain in detail how it fails to work.
If it works perfectly except for the deadtime delay being too small,
then say so. Explain in detail how it fails.

3. Post your compiler version.

If you do those three things, I can probably make it work.

Your program worked with the pic 18f1330 only.
I changed the program a little to have 2 complementary pwms and a dead time.
My simulator is Proteus 7.5 sp3. It gives me that the cpu load during simulation is around 85% which is too much for a small program, and I always have to give power to the mclr pin.
When I tried to change include 18f1330 to 18f4331, no pwm outputs are shown and the simulator gives me this message:
Quote:

The SCSx bits cannot be set. oscillator switching is not enabled in the configuration bits

Please help me. I would go for the pic 18f1330 but the cpu load is too much and it reaches 100% when I use a frequency of 10KHz (the frequency I need), of course all of this is happening and I didn't include in my program the analog to digital conversion.
By the way this is my code:
Code:

#include<18F1330.h>
#fuses INTRC_IO, NOWDT, NOPROTECT, NOBROWNOUT, PUT
#use delay(clock=8000000)

#define POWER_PWM_PERIOD 1999  // 1 KHz pwm freq with 8 MHz osc.

//=======================================
void main()
{

// Setup the 4 Power PWM channels as ordinary pwm channels.
setup_power_pwm_pins(PWM_COMPLEMENTARY, PWM_off, PWM_Off, PWM_Off);

// Mode = Free Run
// Postscale = 1   (1-16) Timebase output postscaler
// TimeBase = 0   (0-65355) Initial value of PWM Timebase
// Period = 2000  (0-4095) Max value of PWM TimeBase
// Compare = 0     (Timebase value for special event trigger)
// Compare Postscale = 1 (Postscaler for Compare value)
// Dead Time

setup_power_pwm(PWM_FREE_RUN, 1, 0, POWER_PWM_PERIOD, 0, 1,30);

set_power_pwm0_duty((int16)((POWER_PWM_PERIOD *4) * .5)); // 10%

while(1);
}

Any help is appreciated.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Apr 29, 2010 12:02 pm     Reply with quote

CPU load ? It's a hardware module in the PIC. It runs independently of
the PIC's CPU. There is no load on the PIC.

If you mean CPU load of Proteus doing the simulation, then get a faster
PC with more RAM perhaps. Ultimately you have to run it in real
hardware (I assume, unless this is just an exercise), so the CPU load
shouldn't be relevant. If it is a concern, then just test the code in
sections. Test the Power PWM. Then comment it out and test the rest
of your program.
wewe



Joined: 17 Apr 2010
Posts: 31

View user's profile Send private message

PostPosted: Thu Apr 29, 2010 12:29 pm     Reply with quote

PCM programmer wrote:
CPU load ? It's a hardware module in the PIC. It runs independently of
the PIC's CPU. There is no load on the PIC.

If you mean CPU load of Proteus doing the simulation, then get a faster
PC with more RAM perhaps. Ultimately you have to run it in real
hardware (I assume, unless this is just an exercise), so the CPU load
shouldn't be relevant. If it is a concern, then just test the code in
sections. Test the Power PWM. Then comment it out and test the rest
of your program.

When I change the frequency to 10KHz I get the message that real time simulation is not working anymore due to CPU load
and yes I have to run it in real hardware, it's a graduation project and not an exercise.
As for the code, do you have any idea why for the same code it's running for a 4331 and not for a 1330? It gives me that message about the SCSx bits cannot be changed ......
And is that 1330 suitable for a dc motor control ?? Because I will have to use a feedback for speed, so I will use 2 analog to digital converters, the first to set the speed and the other for feedback (and I may need a third, who knows).
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Apr 29, 2010 12:40 pm     Reply with quote

I don't have Proteus. I can't debug any problem with it.

See this post for information about using the Power PWM functions
with the 18F1330:
http://www.ccsinfo.com/forum/viewtopic.php?t=30061&start=7
MikeP



Joined: 07 Sep 2003
Posts: 49

View user's profile Send private message

PostPosted: Thu Apr 29, 2010 9:15 pm     Reply with quote

You can only use that CPU load in Proteus as general idea of CPU load as you move along in a project and make changes.

For one a while loop will use 100% of the CPU time. The PWM is a hardware module will run in the back ground after its setup.

I see in your code

Code:


while(1);



Proteus is no sub for real hardware. I use both, Proteus does save me a lot of time by letting me see changes to LCD user interface code without a lot of writes to real hardware.

Its also a helpful tool for debugging once you understand how to use it.

I have never tried to sim PWM I would say you should ask on the Proteus user forums some of the questions you have.



Quote:

The SCSx bits cannot be set. oscillator switching is not enabled in the configuration bits


One or two things are happening here. Does CCS even support the 18F1331 or Proteus doesn't support the 18f1331. I am a few versions back on CCS C 4.101 but i don't have a 18f1331.h file.

From the sound of it CCS is not setting the right config bits for this PIC or there are new #fuse defines in the 18f1331.h file that will fix this error.

Maybe someone else can help you with the #fuse line to you should use with the 18F1331 to fix this error if they think its also a problem with the #fuse line you are using not setting the right config bits.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2, 3, 4  Next
Page 3 of 4

 
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