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

Pic18F46K22 PWM
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Jan 28, 2011 4:19 pm     Reply with quote

To make CCP2 work with vs. 4.114 with the 18F45K22 (or 18F46K22)
you need to use the substitute routine "my_setup_ccp2()" shown below.
That's because setup_ccp2() is buggy in vs. 4.114 for this series of PICs.
Code:

#include <18F45K22.h>
#fuses INTRC_IO,NOWDT,PUT,BROWNOUT,NOLVP 
#use delay(clock=4000000)


#byte T2CON = 0xFBA
#byte PR2 = 0xFBB

#define setup_timer_2(prescaler, PR2val, postscaler) \
if(prescaler)   \
  {             \
   PR2 = PR2val;  \
   T2CON =  prescaler | ((postscaler -1) << 3);  \
  }             \
else            \
  T2CON = 0;


#byte CCP2CON  = 0xF66
#byte PWM2CON  = 0xF65
#byte ECCP2AS  = 0xF64
#byte PSTR2CON = 0xF63

void my_setup_ccp2(int32 mode) 
{
output_low(PIN_C1);   // This assumes "standard i/o" mode is used
CCP2CON = make8(mode, 0);             
PWM2CON = 0;             
ECCP2AS = make8(mode, 2);     
if(make8(mode, 3) == 0x00)  // If no steering pin was specified, use P1A
   PSTR2CON = 1;         
}


//======================================
void main(void)
{
setup_timer_2(T2_DIV_BY_1, 255, 1);
setup_ccp1(CCP_PWM);   
my_setup_ccp2(CCP_PWM);   

set_pwm1_duty(64);
set_pwm2_duty(128);
while(1);
 
}
 
NivNavick



Joined: 01 Nov 2010
Posts: 47

View user's profile Send private message

PostPosted: Fri Jan 28, 2011 4:43 pm     Reply with quote

NivNavick wrote:
When I'm adding CCP2 setup it's cancels all the .
It should repair the CCP2 problem?
---.
Can you take a look at the fuses I posted above and please tell
me why CCP3 (PIN_B5) aren't working, (I mean that it's always sends 1(5v) and I can't reset the above pin)?
Maybe one of the fuses refers to Port B and cancel the access to
the pins?

I think the problem could #FUZES NOLVP because it is he NO LOW VOLTAGE on B5 meaning high voltage,could it be the problem with CCP3?

Thanks!!!


thank you very much!!!!!!!!!!!!

Do you know how to fix CCP3 ?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Jan 28, 2011 4:56 pm     Reply with quote

Well, probably. But why do I have to do all the work ? Why don't you try.
NivNavick



Joined: 01 Nov 2010
Posts: 47

View user's profile Send private message

PostPosted: Sat Jan 29, 2011 1:39 am     Reply with quote

PCM programmer wrote:
Well, probably. But why do I have to do all the work ? Why don't you try.



I tried and my thought are that the NOLVP is the problem, but I'm not sure,
do you think it's the problem too?
Ttelmah



Joined: 11 Mar 2010
Posts: 19504

View user's profile Send private message

PostPosted: Sat Jan 29, 2011 5:01 am     Reply with quote

No.
NOLVP, is _required_, if you are going to use the LVP programming pins for anything _but_ programming. If LVP is enabled, these pins become 'unusable', which matches what you are seeing. LVP, should _only_ be enabled if you are using a low voltage programmer that uses these pins (99.9% of programmers don't). One (faint) possibility would be, that you _are_ using such a programmer, and it's software automatically turns off the NOLVP setting, making the pins unusable.....

Best Wishes
NivNavick



Joined: 01 Nov 2010
Posts: 47

View user's profile Send private message

PostPosted: Sun Jan 30, 2011 1:11 am     Reply with quote

Code:
#fuses INTRC_IO//,NOLVP

when the above fuse is in my program the clock are messed up
and if I delete the fuse the clock value which was 20MH is fine

I mean with delay_ms(1); it's look like 1 sec

what is the problem?
Ttelmah



Joined: 11 Mar 2010
Posts: 19504

View user's profile Send private message

PostPosted: Sun Jan 30, 2011 3:26 am     Reply with quote

Your timings are not going to work, because you are using an impossible combination. The internal RC oscillator, _does not offer 20MHz as an available speed_.
You _must_ start by reading the data sheet, and only using options supported by the chip you are using.

Best Wishes
NivNavick



Joined: 01 Nov 2010
Posts: 47

View user's profile Send private message

PostPosted: Sun Jan 30, 2011 1:01 pm     Reply with quote

When I programmed on the 18F4520 I had two methods,
I that return value from Ultra Sonic Ranger(SRF05) and the second return angle from CMPS03

from when I added the PWM bug fix those two methods aren't working any more, I think the pins are not changed to input and they are only outputs even I write SET_TRISA(0b000001);

What could be the problem?

Thanks!!
NivNavick



Joined: 01 Nov 2010
Posts: 47

View user's profile Send private message

PostPosted: Mon Jan 31, 2011 9:10 am     Reply with quote

Does anybody knows?
NivNavick



Joined: 01 Nov 2010
Posts: 47

View user's profile Send private message

PostPosted: Tue Feb 01, 2011 9:59 am     Reply with quote

hi

I have a month until my final project which I am working in it right now,
please answer
Smile
NivNavick



Joined: 01 Nov 2010
Posts: 47

View user's profile Send private message

PostPosted: Wed Feb 02, 2011 12:04 am     Reply with quote

I talked to CCS support and they told ne that
CCP3 registers aren't correct,
Is there anybody that know how to setup the
CCP3 registers and fix them?

Thanks
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Feb 02, 2011 12:55 am     Reply with quote

I showed you how to make a work-around routine for CCP2 in this post:
http://www.ccsinfo.com/forum/viewtopic.php?t=44564&start=8
Just do it the same way for CCP3.
Copy the #byte statements and change the register names so they
refer to CCP3 instead of CCP2. Look up the addresses of the CCP3
register in the PIC data sheet. Enter them into the new #byte
statements.

Make a copy of the "my_setup_ccp2()" routine and rename it for ccp3.
Edit the register names in the new function so they are the ones
associated with CCP3. Look up the default pin for CCP3 PWM output
in the PIC data sheet and edit the output_low() statement to use that pin.

Then in main(), call my_setup_ccp3(CCP_PWM) and set_pwm3_duty(128).
CCP3 also uses Timer2 by default, so the setup_timer_2() function will
work and can be left unchanged. The set_pwm3_duty() function
should also work without any changes.

It's really quite easy to make these changes, and they will probably work
if you're careful.
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 1, 2  Next
Page 1 of 2

 
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