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

PWM problem on 18F45K40

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



Joined: 15 Dec 2018
Posts: 5

View user's profile Send private message

PWM problem on 18F45K40
PostPosted: Sun Dec 16, 2018 3:21 pm     Reply with quote

I'm having issues with the setup and running of the CCP1 PWM on the 18F45K40.

CCS Complier V5.081

The 18F45K40 is a new to me as is the latest compiler version. I have confirmed PWM works with my old 16F1826 and new compiler V5.081.

With the 18F45K40 have confirmed Digital I/Os are working OK, Analogs inputs are OK, I2C is OK, TXD is OK BUT PWM is stopping when at a low duty cycle and not recovering until power is reset.

In the stripped back code below the PWM stopped when it gets to the (long) numbers 17 to 22 (all other number are fine), if I use (int) numbers then it stops when 5 or 6 are used and all other numbers are fine.

The other issue I have (which may be related) is the PWM does not run after a program load using pickit3, it requires a power reset for the PWM to start. Yet immediately after a program load I can see the pic is running as TXD is working (when I had it enabled).

Any tips on this would be appreciated!


Code:

#include <18F45K40.h>
#FUSES NOEXTOSC                 
#FUSES NOMCLR                   
#FUSES NOBROWNOUT
#FUSES NOWDT
//#use delay(internal  = 64M)
#use delay(internal  = 16M)

#PIN_SELECT CCP1OUT = PIN_C2

#define  TRIS_A_VALUE 0b00010110         
#define  TRIS_B_VALUE 0b11111111
#define  TRIS_C_VALUE 0b10111001              
#define  TRIS_D_VALUE 0b01111110
#define  TRIS_E_VALUE 0b00001000

//#use rs232(baud=9600,xmit=PIN_A3,FORCE_SW, stream = debug)
//#use rs232(baud=9600,xmit=PIN_C6,rcv=PIN_C1, stream = xbee)

void main()
{
//setup_oscillator(OSC_HFINTRC_64MHZ);
set_tris_a( TRIS_A_VALUE );
set_tris_b( TRIS_B_VALUE );
set_tris_c( TRIS_C_VALUE );
set_tris_d( TRIS_D_VALUE );
set_tris_e( TRIS_E_VALUE );

setup_ccp1 (CCP_PWM);
output_drive(PIN_C2);

//setup_timer_2(T2_CLK_MFINTRC | T2_DIV_BY_1, 99, 1);   
setup_timer_2(T2_CLK_INTERNAL | T2_DIV_BY_128, 99, 1);
set_pwm1_duty(0);

while( TRUE )
{           
    long i;
    for(i=0; i<99; i++)
    {
        //fprintf(debug,"i = %lu \r\n", i);
        set_pwm1_duty(i); 
        delay_ms(1000);
    } 

}   

}
Ttelmah



Joined: 11 Mar 2010
Posts: 19538

View user's profile Send private message

PostPosted: Mon Dec 17, 2018 2:44 am     Reply with quote

Your startup issue, is almost certainly the hardware limit timer.

T2, on this chip has the ability to be run as a monostable, as well as a
free running timer, and be triggered by external sources. You need to
disable this to have it free run as a conventional timer:

setup_timer_2(T2_CLK_INTERNAL | T2_DIV_BY_128 | T2_START_IMMEDIATELY, 99, 1);

It's probably waking intermittently with the enable off...

It's possible that the control for this is defaulting to a pin that is affected
by the PWM, so this is the other problem as well, though I cannot
immediately see this.

I can't see anything else. You do realise you will only get to a 25% duty
cycle with your numbers?.
srtgumbee



Joined: 15 Dec 2018
Posts: 5

View user's profile Send private message

PostPosted: Tue Dec 18, 2018 7:19 pm     Reply with quote

Hi Ttelmah,

Thank you for your reply and hints. Short answer - The PWM on the 18F45K40 is and was always operating correctly!

Based on your information I started investigating the hardware more thoroughly and found the 12V DCDC power supply which was powering my LED was shutting down when PWM was ~5%.
The PIC was running perfectly, but I had no visual output or on the scope and having just tested the same output with a 1hz 'blink led' I was lead down the path the PWM was the cause of my issues.

Thanks again for your contribution, it helped me come to my senses!
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