|
|
View previous topic :: View next topic |
Author |
Message |
mvanvliet
Joined: 02 Jun 2009 Posts: 123 Location: The Netherlands
|
8 bits CCP PWM on 16F18324 |
Posted: Wed Feb 15, 2017 4:24 am |
|
|
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
|
|
Posted: Wed Feb 15, 2017 5:27 am |
|
|
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
|
|
Posted: Wed Feb 15, 2017 5:37 am |
|
|
The multiply by 4 was also my quick solution. Unfortunately there is no other solution. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19561
|
|
Posted: Wed Feb 15, 2017 12:03 pm |
|
|
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); |
|
|
|
|
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
|