Milentije89
Joined: 07 Apr 2017 Posts: 31
|
#USE PWM and bootloader [18F26K22] |
Posted: Fri Mar 27, 2020 5:50 am |
|
|
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. |
|