![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
Mobotix Guest
|
PCD: PWM on pic24 |
Posted: Sun Feb 14, 2010 11:06 am |
|
|
Did someone try to run PWM on PIC24 ?
I need it for few things and one on them is lcd. |
|
![](templates/subSilver/images/spacer.gif) |
bkamen
Joined: 07 Jan 2004 Posts: 1611 Location: Central Illinois, USA
|
|
Posted: Sun Feb 14, 2010 11:28 am |
|
|
I have.
What do you want to know?
(I was using PWM to generate a test clock for debugging)
-Ben _________________ Dazed and confused? I don't think so. Just "plain lost" will do. :D |
|
![](templates/subSilver/images/spacer.gif) |
Mobotix Guest
|
|
Posted: Mon Feb 15, 2010 1:46 am |
|
|
I will PM you.
Regards ! |
|
![](templates/subSilver/images/spacer.gif) |
bkamen
Joined: 07 Jan 2004 Posts: 1611 Location: Central Illinois, USA
|
|
Posted: Mon Feb 15, 2010 9:24 am |
|
|
I recently used timers and PWM on a PIC24FJ256GA110 and it looked something like this: (you WILL need to change to suit your project. At least this gives you some starting settings.)
Code: | #include <24FJ256GA110.h>
#fuses NOJTAG, NOPROTECT, NOWRT, NOIESO
#fuses WDT, WPRES32, WPOSTS14
#fuses NOCKSFSM, NOOSCIO, ICSP2
#use delay (clock=32M, crystal=8M) // XT is ok for 8MHz
#zero_ram
#opt 11
#word PR1 = getenv("sfr:PR1")
#word PR2 = getenv("sfr:PR2")
#word RCON = getenv("sfr:RCON")
#word OC1CON2 = getenv("sfr:OC1CON2")
#word OC1R = getenv("sfr:OC1R")
#word OC1RS = getenv("sfr:OC1RS")
#pin_select OC1 = PIN_D0
// =============================================
//
//
//*PURPOSE General Purpose System Timer Interrupt
#INT_TIMER1
void timer1_isr ( void ) {
output_toggle(LED_HEARTBEAT);
if (!timer_counter--) {
timer_counter = 9;
if (!timer_event) {
timer_event = 1;
}
}
}
void main (void) {
// --------------------------------------------
// Set up system heartbeat timer. (this can't be PWM, Software pacing is required
setup_timer1 (TMR_INTERNAL | TMR_DIV_BY_256);
PR1 = 6250;
// -Set up PWM for interrupt/software free test clock generation-----------------
setup_timer2 (TMR_INTERNAL | TMR_DIV_BY_8);
PR2 = 101; // 16MHz / 8 = 2,000,000 / 100 = 20,000 / 2 = 10KHz
// -----TOGGEL is spelled wrong in .H file for PIC. To be fixed in next CCS release.
setup_compare(1, COMPARE_TOGGEL | COMPARE_SYSTEM_CLOCK | COMPARE_TRIG_SYNC_TIMER2);
OC1R = 405;
OC1RS = 0x1;
OC1CON2 |= 0x20;
output_low(PIN_D0);
while(1) {
if (timer_event) {
timer_event = 0;
do_stuff();
}
}
}
|
_________________ Dazed and confused? I don't think so. Just "plain lost" will do. :D |
|
![](templates/subSilver/images/spacer.gif) |
Guest User Guest
|
|
Posted: Mon Feb 22, 2010 12:39 pm |
|
|
I have almost the same project.
I have to shut down the lcd and this is working but program hangs in some parts. E.g. if you press key, program goes to sleep but if you press the key again in cca 1 sec program hangs or is not responding to new command.
On the other hand, sometime program just stop to work and you get sleep.. all the time.
Any idea ?
Code: | //------------------------
int count=0;
int1 sleep=0;
//-------------------------
void wake_up(void) {
int i;
lcd_putc("Wakeup..");
for(i=0;i<816;i++) { //806
OC1RS=i;
delay_ms(10);
}
page=0;
state=0;
level=0;
}
//------------------------------
void go_sleep(void) {
int i;
lcd_putc("sleep...");
for(i=805;i>0;i--) { //805
OC1RS=i;
delay_ms(10);
}
}
// ISR == each 1 sec
#INT_TIMER1
void timer1_isr(void) {
count++;
if(count==15 && sleep==0)
{
go_sleep();
//awake=0;
sleep=1;
count=0;
}
}
//----------------------
setup_timer1(TMR_INTERNAL|TMR_DIV_BY_256);
enable_interrupts(INT_TIMER1);
enable_interrupts(GLOBAL);
// main
do
{
k=kbd_getc();
if (k) {
if(sleep==1) {
wake_up();
count=0;
sleep=0;
}
} |
|
|
![](templates/subSilver/images/spacer.gif) |
|
|
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
|