View previous topic :: View next topic |
Author |
Message |
Antony77
Joined: 17 Jul 2010 Posts: 3
|
PWM not work on 12f683 |
Posted: Sat Jul 17, 2010 3:33 am |
|
|
Hi I wrote this code to generate a frequency of 1MHz with a 12f683 using an external 20MHz quartz ... why not working? here's the code:
Code: | #include <12F683.h>
#device adc=8
#FUSES NOWDT //No Watch Dog Timer
#FUSES HS //High speed Osc (> 4mhz for PCM/PCH) (>10mhz for PCD)
#FUSES NOCPD //No EE protection
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOMCLR //Master Clear pin used for I/O
#FUSES NOPUT //No Power Up Timer
#FUSES NOBROWNOUT //No brownout reset
#FUSES IESO //Internal External Switch Over mode enabled
#FUSES FCMEN //Fail-safe clock monitor enabled
#use delay(clock=20000000)
void main()
{
setup_adc_ports(NO_ANALOGS|VSS_VDD);
setup_adc(ADC_CLOCK_DIV_2);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DIV_BY_1,3,1);
setup_ccp1(CCP_PWM);
set_pwm1_duty(0);
setup_comparator(NC_NC);
setup_vref(FALSE);
while (1)
{
delay_cycles(1);
}
} |
Last edited by Antony77 on Sat Jul 17, 2010 6:24 am; edited 1 time in total |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19503
|
|
Posted: Sat Jul 17, 2010 6:18 am |
|
|
setup_timer_2(T2_DIV_BY_1,4,1); //Gives clock/(4*5)
Set_pwm1_duty(10L); //Need the 'L' to give 10 counts of the master clock
At the moment, you have no 'on' period, so no output.... |
|
|
Antony77
Joined: 17 Jul 2010 Posts: 3
|
|
Posted: Sat Jul 17, 2010 6:21 am |
|
|
Oh I forgot to set the duty at 50%...What value should I use for 50%?
Why L? and why "setup_timer_2(T2_DIV_BY_1,4,1); //Gives clock/(4*5)" ? |
|
|
|