|
|
View previous topic :: View next topic |
Author |
Message |
cvargcal
Joined: 17 Feb 2015 Posts: 134
|
Configure timer2 18LF26K22 |
Posted: Wed Aug 18, 2021 8:46 pm |
|
|
Hi, I want configure this code
http://www.ccsinfo.com/forum/viewtopic.php?t=58152
Code: | //compiler ver 4.140
#include <24hj12gp201.h>
#FUSES NOWDT //No Watch Dog Timer
#FUSES NOJTAG //JTAG disabled
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOWRT //Program memory not write protected
#FUSES NODEBUG //No Debug mode for ICD
#FUSES NOIOL1WAY //Allows multiple reconfigurations of peripheral pins
#FUSES NOWINDIS //Watch Dog Timer in Window mode
#FUSES WPRES128 //Watch Dog Timer PreScalar 1:128
#FUSES WPOSTS16 //Watch Dog Timer PostScalar 1:32768
#FUSES NOIESO //Internal External Switch Over mode disabled
#FUSES FRC //Internal Fast RC Oscillator
#FUSES NOCKSFSM //Clock Switching is disabled, fail Safe clock monitor is disabled
#FUSES NOOSCIO //OSC2 is general purpose output
#FUSES NOPR //Pimary oscillaotr disabled
#use delay(clock=80M,internal)//internal oscillaotr with PLL at 80Mhz (40MIPS)
#use standard_io(all)
#PIN_SELECT OC1=PIN_B4 //remappable peripheral pin assigned to Output Compare 1
// PIC TCD1304AP
//B7(pin 10)---->ICG(pin3)
//B4( pin 8)---> Mc (pin4) 1Mhz PWM
//B9(pin 12)---> SH (pin5)
#define ICG PIN_B7
#define SH PIN_B9
int16 shutter=1;
void main()
{
//setup PWM1 to 1MHZ 50%
setup_timer2(TMR_INTERNAL | TMR_DIV_BY_1, 39);
setup_compare(1, COMPARE_PWM | COMPARE_TIMER2);
set_pwm_duty(1, 19);
//initial state of control pin
output_bit( SH, 0);
output_bit( ICG, 1);
for(;;)//main loop
{
//sync to rise edge of master clock
while (input_state(PIN_B4)==1);//check logical level of master clock pin B4
while (input_state(PIN_B4)==0);
while (input_state(PIN_B4)==1);
delay_cycles(20 );
output_bit( ICG, 0);
delay_cycles(20);
output_bit( SH, 1);
delay_us(5);
while (input_state(PIN_B4)==1);//check logical level of master clock pin B4
output_bit( SH, 0);
delay_us(3);
while (input_state(PIN_B4)==0);//check logical level of master clock pin B4
while (input_state(PIN_B4)==1);
while (input_state(PIN_B4)==0);
delay_cycles( 1 );
output_bit( ICG, 1);
delay_us(5);
output_bit( SH, 1);
delay_us(5);
//generate electric shutter
for(shutter=1;shutter<800;shutter++)
{
output_bit( SH, 0);
delay_us(15);
output_bit( SH, 1);
delay_us(5);
}
}//main loop
}//main |
To PIC 18LF26K22 I dont get configure the timer...please someone can help me? thanks |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19590
|
|
Posted: Thu Aug 19, 2021 3:17 am |
|
|
This is a read the manual one.....
The Timer2 setup for the PIC24, is different from the PIC18.
Look at the PWM example files. Three values needed for the timer setup.
Also different peripheral (CCP, instead of output_compare), and very different
frequencies possible. |
|
|
jeremiah
Joined: 20 Jul 2010 Posts: 1358
|
|
Posted: Thu Aug 19, 2021 6:55 am |
|
|
You can also instead use #use PWM() for a more generic PWM setup that works across a lot more chips. You just tell it the timer and a few other info about what you want and it configures everything for you based on the available hardware for the chip and will emit warnings/notes if it can't quite do that with your chip. |
|
|
|
|
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
|