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

Slow PWM with 16MHz clock....

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



Joined: 21 Nov 2003
Posts: 200

View user's profile Send private message

Slow PWM with 16MHz clock....
PostPosted: Mon Mar 05, 2012 11:17 pm     Reply with quote

I am working on way too many projects but i am faced with another issue. I am trying to run a 80Hz PWM but I am running at 16MHz on the clock. I am using the 18F88k22 and PWM 9 to do the work. Using an internal osc for this one as well as I dont have any pins left over for another clock.
I have tried to use a timer with a little program to make one but I am also running a display that needs to refresh and the timer slows everything down too much. So let me know if you guys have some thoughts.. Thanx as always..

CCS 4.128
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Mar 05, 2012 11:24 pm     Reply with quote

There is no 18F88k22, and as always, post a short test program that
shows the problem.
gpsmikey



Joined: 16 Nov 2010
Posts: 588
Location: Kirkland, WA

View user's profile Send private message

PostPosted: Mon Mar 05, 2012 11:26 pm     Reply with quote

PCM programmer wrote:
There is no 18F88k22, .....


Ah ha !! That must be the problem ...
_________________
mikey
-- you can't have too many gadgets or too much disk space !
old engineering saying: 1+1 = 3 for sufficiently large values of 1 or small values of 3
curt2go



Joined: 21 Nov 2003
Posts: 200

View user's profile Send private message

PostPosted: Tue Mar 06, 2012 11:55 am     Reply with quote

Smile

Thanx.. Typo... 18F87K22....
Code:

#include <18F87K22.h>
#device ICD=TRUE
#device adc=10 *=16

#FUSES NOWDT                    //No Watch Dog Timer
//#FUSES WDT128                   //Watch Dog Timer uses 1:128 Postscale
#FUSES INTRC_IO                       //High speed Osc (> 4mhz)
#FUSES PROTECT                  //Code protected from reads
#FUSES NOIESO                     //Internal External Switch Over mode enabled
#FUSES BROWNOUT                  //No brownout reset
//#FUSES BORV45                   //Brownout reset at 2.5V
#FUSES PUT                      //Power Up Timer
#FUSES NOCPD                    //No EE protection
#FUSES STVREN                   //Stack full/underflow will cause reset
#FUSES DEBUG                     //No Debug mode for ICD
//#FUSES NOLVP                      //Low Voltage Programming on B3(PIC16) or B5(PIC18)
#FUSES NOWRT                    //Program memory not write protected
#FUSES NOCPB                    //No Boot Block code protection
#FUSES NOEBTRB                  //Boot block not protected from table reads
#FUSES NOEBTR                   //Memory not protected from table reads
#FUSES NOWRTD                   //Data EEPROM not write protected
#FUSES NOWRTC                   //configuration not registers write protected
#FUSES NOWRTB                   //Boot block not write protected
#FUSES FCMEN                    //Fail-safe clock monitor enabled
//#FUSES LPT1OSC                  //Timer1 configured for low-power operation
#FUSES NOMCLR                     //Master Clear pin enabled
#FUSES NOXINST                  //Extended set extension and Indexed Addressing mode disabled (Legacy mode)
#FUSES BBSIZ1K                  //1K words Boot Block size
//#FUSES CCP2C1
//#FUSES PLLEN                     //enable the PLL
#use delay(clock=16000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,errors)
//#use i2c(Master,Fast,sda=PIN_D5,scl=PIN_D6)


void main(){

setup_ccp9(CCP_PWM | CCP_USE_TIMER7_AND_TIMER4);
setup_timer_4(T4_DIV_BY_16, 0xff,1);
setup_oscillator(OSC_16MHZ );

while(true){
set_pwm9_duty(200);
}

}
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Tue Mar 06, 2012 2:54 pm     Reply with quote

i don't see how you can get a basic PWM frequency any lower than about
1 khz at 10 bit resolution , based on a quick read of the datasheet

80 hz seems out of the question based on the frequency equations in the datasheet
Ttelmah



Joined: 11 Mar 2010
Posts: 19328

View user's profile Send private message

PostPosted: Tue Mar 06, 2012 3:12 pm     Reply with quote

Unlike most of the older PICs where the PWM runs only off the master oscillator, on these latter PIC's you do have the option of running the PWM, from a timer that is running another clock.
You can generate a slow hardware PWM two ways:
1) Run a separate slow oscillator.
2) Cascade - run a PWM using the master oscillator output from (say) PWM1, and feed this into the clock input of another timer (T1CKI for example).
You can then generate really nice slow PWM outputs if required.

Best Wishes
curt2go



Joined: 21 Nov 2003
Posts: 200

View user's profile Send private message

PostPosted: Tue Mar 06, 2012 3:58 pm     Reply with quote

But that wold be a hardware change correct ? You are saying make a pwm at X frequency and feed that from the PWM output into a clock input and then use that frequency to generate an even lower pwm frequency on another pwm. Or am I missing something. I am looking for a software solution but if there isn't one then that may be my best option. I have run out of pins the the pic though so it will be extremely tough.

Let me know if I got your thoughts right Ttelmah? Thanx TTY
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Tue Mar 06, 2012 5:48 pm     Reply with quote

You got his thoughts exactly right.
The nice thing about working with PICs is how you can blend hardware and software TOGETHER to get a solution.
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