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

#USE PWM and bootloader [18F26K22]

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



Joined: 07 Apr 2017
Posts: 10

View user's profile Send private message

#USE PWM and bootloader [18F26K22]
PostPosted: Fri Mar 27, 2020 5:50 am     Reply with quote

Hello to you all!

I am having a bit of a problem. I have found the source of a problem, and also found the solution. But, I am not satisfied with the solution, so I am opening this thread.

MCU: PIC18F26K22 @5V
Compiler version: 5.075

I am using PWM for driving a buzzer. PWM output pin is B3.

PWM is set using #USE PWM

Code:
#use PWM (STREAM = BUZZ, PWM2, OUTPUT = PIN_B3, TIMER = 2, FREQUENCY=2730, DUTY = 50, PWM_OFF)


PWM is working when HEX is programmed directly (without bootloader).

When I program the MCU using bootloader with the same HEX (addresses are set correctly ofcourse), everything works except the PWM.

Then I added #USE PWM line to the bootloader and programmed everything again. Now, PWM works when HEX is programmed via bootloader.

Checking the .LST file i saw some fuses that are setting CCP2 and CCP3 in/out. That is how I found the source of a problem.

But, for everything to work, I have to have #USE PWM line in bootloader as well as in "main" program. If I delete #USE PWM line from main program then none of the functions related to PWM doesn't work (PWM is not initiated/setup correctly).

Is there a way around this problem? I would like to evade adding #USE PWM line in a bootloader.

TIA,
Milos

EDIT: Sorry, I posted this thread in wrong subforum... It should be in General Discussion. My bad, sorry.

EDIT 2: There is a solution. Just add CCP2B3 fuse in bootloader.
Ttelmah



Joined: 11 Mar 2010
Posts: 15749

View user's profile Send private message

PostPosted: Fri Mar 27, 2020 7:18 am     Reply with quote

Yes.

If you looked at the .LST for the main program you would see that the
#USE PWM line resulted in this fuse being added to the code.

Now the fuses the bootloader programs must always match what the
'main' needs to have....
Milentije89



Joined: 07 Apr 2017
Posts: 10

View user's profile Send private message

PostPosted: Fri Mar 27, 2020 7:29 am     Reply with quote

It is good to talk with yourself from time to time. It helps you solve the problem. Very Happy
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