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

8 bits CCP PWM on 16F18324

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



Joined: 02 Jun 2009
Posts: 123
Location: The Netherlands

View user's profile Send private message

8 bits CCP PWM on 16F18324
PostPosted: Wed Feb 15, 2017 4:24 am     Reply with quote

In my opinion it was in the 16F1823/1824 series that the CCP PWM module was standard 8 bits and after using a 16 bits variable or placing an 'L' behind the variable the CCP PWM is working at 10 bits. But now I'm using the 16F18324 and this module is always using 10 bits. Because I'm migrating an old program for 16F1824 to 16F18324 I would like to keep as much the same as possible, but for me it isn't working. Does anyone know how to use an 8 bits CCP PWM module instead of the 10 bits?

CCS version: 5.062

Test program (so this is not my final program!):
Code:

#include <16F18324.h>

#FUSES RSTOSC_HFINTRC_PLL,NOWDT
#FUSES NOPUT,NOMCLR,NOPROTECT,NOCPD,BROWNOUT,BORV24                              //PUT voor 64ms delay bij opstarten en bij brown-out
#FUSES NOCLKOUT,PUT
#FUSES NOFCMEN
#FUSES NOSTVREN,NODEBUG,NOLVP

#use delay(clock=8000000)

#pin_select CCP1OUT = PIN_C5

int8 i = 0;

main()
{
setup_oscillator(OSC_HFINTRC_8MHZ);
setup_CCP1(CCP_PWM|CCP_TIMER4);
setup_timer_4(T4_DIV_BY_1,255,1); 

while(1)
   {
   
   for(i = 0; i<255; i++)
      {
      set_PWM1_duty(i);
      delay_ms(10);
      }

   }
}


In my opinion this should be a duty cycle from 0 to 100%, but because of the 10 bits PWM it is from 0 to 25%.[/quote]
Ttelmah



Joined: 11 Mar 2010
Posts: 19561

View user's profile Send private message

PostPosted: Wed Feb 15, 2017 5:27 am     Reply with quote

This is because of the fundamentally 'different' PWM on this chip.

On the standard PIC's, there is an 8bit PWM register, and then two separate 'extra' low bits stored into another register. Using an int8, only accesses the main 8bit register.
On this PIC, there are instead two PWM registers giving you full 16bit PWM control. To actually use it in a mode 'akin' to the older chip, you'd have to multiply your PWM duty value by 4.

If you look in the header file for the chip, you will find the duty prototype, only accepts an int16.


Last edited by Ttelmah on Wed Feb 15, 2017 8:19 am; edited 1 time in total
mvanvliet



Joined: 02 Jun 2009
Posts: 123
Location: The Netherlands

View user's profile Send private message

PostPosted: Wed Feb 15, 2017 5:37 am     Reply with quote

The multiply by 4 was also my quick solution. Unfortunately there is no other solution.
Ttelmah



Joined: 11 Mar 2010
Posts: 19561

View user's profile Send private message

PostPosted: Wed Feb 15, 2017 12:03 pm     Reply with quote

The compiler will code a *4, as a binary shift, so very quick, but it is fundamental to the nature of the chip.

With the standard 10bit PWM, you have

rrrrrrrrxx

Where 'r' are bits in the register, and 'xx' are the two extra bits stored separately.

While with this pwm, you have

hhhhhhhhrrrrrrrr

Stored in two registers (h is the high register).

If you code the pwm to use 1/4 the divider, and then a 4* larger prescaler, the LSb of the value will give the same result as you get from the 10bit PWM.

setup_timer_4(T4_DIV_BY_4,63,1);
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