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

help in writing in C language for a pic18f4331
Goto page Previous  1, 2, 3, 4
 
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: Thu Apr 29, 2010 11:52 pm     Reply with quote

Mike, the PIC is 1330 and not 1331, and the problem of these configuration bits things is happening with the pic4331 and not with the 1330.
My problem with the 1330 is the CPU load.
Anyway guys, you have seen 2 functioning programs that I mentioned in this thread.
The first was an analog to digital converter (and it worked in Proteus with the 4331) and the other is the power pwm that only worked with the 1330.
Now I need to combine both and my program is almost done. The result of the analog to digital conversion will determine my duty cycle. The frequency is stable at 10Khz (period=199 for a 8 mhz oscillator).
Can someone combine these 2 programs in one program ???
And by the way if i didn't use Proteus I would probably never have found out that if I don't feed the MCLR pin the program might not work.
and is there any other simulater (other than proteus , that works the same way , i will gladly get it if it works)
and PCM programmer , yes your program works , and as i said before it's on the pic 1330 , and i edited it and had successfully generated 2 complementary pwms but that cpu load was my problem , while your original program that generated 3 power pwms without their complementary worked with a cpu load of 50%
and one more thing , when i create a new source file and i compile , most of the times the output files are generated in another folder that contains another program , why ???
wewe



Joined: 17 Apr 2010
Posts: 31

View user's profile Send private message

PostPosted: Fri Apr 30, 2010 10:28 am     Reply with quote

I think that there's something wrong with my CCS.
I tried to open a new project with the pic 1330.
Anyway without even writing a code i got some errors.
First of all NC_NC_NC not defined
Code:

 setup_comparator(NC_NC_NC_NC); // This device COMP currently not supported by the PICWizard
//Setup_Oscillator parameter not selected from Intr Oscillotar Config tab


In the file 18f1330.h I found that the parameter is declared #define NC_NC_NC 0x00 (there's a " _NC" missing )

And the other error is
Code:

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

USE parameter value is out of range. Not a number PIN_C6.

So the declarations are all wrong
I was thinking about using this 1330 instead of 4331 because the power pwm simulation worked for this 1330 and the same code didn't work for the 4331.
Really there's many things wrong here.
wewe



Joined: 17 Apr 2010
Posts: 31

View user's profile Send private message

PostPosted: Sat May 01, 2010 12:54 am     Reply with quote

Surprisingly my program worked (with the 18f1330).
Now for some more questions.
If I run my program in mplab using the mplab plug-in tool I can burn my program using pickit ? (Someone already answered this but I prefer a much detailed answer if there's any).
Here's my program:
Code:

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

#define POWER_PWM_PERIOD 199  // 10 KHz pwm freq with 8 MHz osc.

//=======================================
void main()
{
int8 result,result1;
setup_adc_ports(all_analog);
setup_adc(ADC_CLOCK_DIV_4);
set_adc_channel(0);
// 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,2);

while (1)
{
result = read_adc();

set_power_pwm0_duty((int8)((result)*7));
}

}

It's working. I chose the period to be result*7 but I should multiply "result" with a factor that gives me a 100% futy cycle if the result of the adc conversion is maximum and 0% if the result of the adc conversion is minimum.
And about this cpu excessive load, does this error exist in pic or only in simulators??
And also I got this message in Proteus:
(ADC conversion clock period (5e-7 violates the minimum required TAD time).
What's that ?
wewe



Joined: 17 Apr 2010
Posts: 31

View user's profile Send private message

PostPosted: Sat May 01, 2010 10:42 am     Reply with quote

Okay it seems like the help reached its limits lol.
Anyway at least can someone help me in burning the program on the pic?
My friend have a programmer and the pickit2 software and I want to take the files for him in order to burn the program on the pic.
Anyway, all I have to do is start a project in mplab and choose ccs compiler and include my source file and then compile in mplab and use the output files to burn the program ?
Is there anything else I need to do ?
wewe



Joined: 17 Apr 2010
Posts: 31

View user's profile Send private message

PostPosted: Mon May 03, 2010 11:32 am     Reply with quote

okay check this weird thing :S
The same code but with include <18f4331.h> doesn't work (the simulation on proteus don't work).
While for include <18f4431.h> it works.
And the Microchip seller near my place only have the 18f4331 .....what do you think I must do ??
There's something wrong with my compiler, right?
wewe



Joined: 17 Apr 2010
Posts: 31

View user's profile Send private message

PostPosted: Tue May 04, 2010 12:13 pm     Reply with quote

Come one just a quick help on the hex file for burning the program on the pic.
If it's not the normal hex file produced on the regular build all from ccs then tell me how to produce the correct hex file.
Do I have to beg ?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue May 04, 2010 1:52 pm     Reply with quote

Take the HEX file produced by "Build all" and go use it with the PicKit 2.
If you need help on using Pickit 2, then read the Pickit 2 manual:
http://ww1.microchip.com/downloads/en/DeviceDoc/51553E.pdf

If you have more questions on how to use the Pickit 2, then ask them
in the Pickit 2 forum on the Microchip website. It's their product.
http://www.microchip.com/forums/tt.aspx?forumid=15
Please don't ask us any more questions about Pickit 2. Ask Microchip.
wewe



Joined: 17 Apr 2010
Posts: 31

View user's profile Send private message

PostPosted: Tue May 04, 2010 9:13 pm     Reply with quote

PCM programmer wrote:
Take the HEX file produced by "Build all" and go use it with the PicKit 2.
If you need help on using Pickit 2, then read the Pickit 2 manual:
http://ww1.microchip.com/downloads/en/DeviceDoc/51553E.pdf

If you have more questions on how to use the Pickit 2, then ask them
in the Pickit 2 forum on the Microchip website. It's their product.
http://www.microchip.com/forums/tt.aspx?forumid=15
Please don't ask us any more questions about Pickit 2. Ask Microchip.

my question is not about pickit2 , my question is "is the hex file produced with the build all directly suitable for use inpickit2 or i have to run the project in mplab environment and then compile and use that hex output file? "
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed May 05, 2010 12:26 am     Reply with quote

I told you the exact answer:
Quote:

Take the HEX file produced by "Build all" and go use it with the PicKit 2.

In fact, bkamen also told you this. You asked:
Quote:
is there anything else that i need to do or just compile my program from mplab and burn it on the pic

bkamen replied:
Quote:
Nope. that should do it.

So each time we give you a direct answer, you ignore it and ask the
same question over and over again. Each time we think we have closed
out the topic, you re-start it again. This is very frustrating to people who
try to help you. I've reached the limit of my patience. I'm not going to
answer any more questions for you.
wewe



Joined: 17 Apr 2010
Posts: 31

View user's profile Send private message

PostPosted: Wed May 05, 2010 9:11 am     Reply with quote

i don't have the programmer at home so i was trying to be sure
i will have to go to a friend's house in order to program my pic and i don't want to go there with the wrong hex file
anyway thx for your patience , and it would be better if other ppl replied me because it's also becoming frustrating to ask questions if this is the attitude i am going to get everytime i ask a question
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
Page 4 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