|
|
View previous topic :: View next topic |
Author |
Message |
nguyentanloc27
Joined: 25 Sep 2013 Posts: 1
|
PWM on pic 24fj256ga106 |
Posted: Wed Sep 25, 2013 2:54 am |
|
|
I' ve tried using pwm on device pic 24fj256ga106. I've tried the #use PWM and also setup_compare(). However, the simulation proteus doesn't display the pwm. Here are my code:
Code: |
#include "24FJ256GA106.h"
#use delay(CLOCK=8000000)
#pin_select OC2 = PIN_B6
#pin_select OC1 = PIN_B1
void main(void) {
setup_timer2(TMR_INTERNAL|TMR_DIV_BY_1,1000);
setup_compare(1,COMPARE_PWM_EDGE | COMPARE_TIMER2 | COMPARE_TRIG_SYNC_TIMER2);
setup_compare(2,COMPARE_PWM_EDGE | COMPARE_TIMER2 | COMPARE_TRIG_SYNC_TIMER2 );
set_pwm_duty(1,200);
set_pwm_duty(2,200);
while(1);
}
|
And this is the #use PWM():
Code: |
#include "24FJ256GA106.h" // Modify for your chip
#use delay(crystal=20000000) // Modify for your clock and freq
#use PWM(OUTPUT=PIN_B1,FREQUENCY=10Khz,DUTY=25)
void main(void) {
PWM_ON();
setup_timer2(TMR_INTERNAL |TMR_DIV_BY_8 ,20000);
set_pwm_duty(1,855);
while(1);
} |
can anyone help me? I'm stuck now. I have to control 18 rc servo in a spider robot. This chip provide 9 pwm with a high resolution, so I chose it. This just the sample code to simulate in proteus, to see if i can controll any servo. Please help me! |
|
|
oxo
Joined: 13 Nov 2012 Posts: 219 Location: France
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19515
|
|
Posted: Wed Sep 25, 2013 8:30 am |
|
|
As a comment though, I'm not sure using the same timer to generate the PWM, and as the sync source is legitimate. Since PWM, is already generated from the timer, just use the timer, don't try to sync to it as well.
Best Wishes |
|
|
|
|
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
|