vinayakdabholkar
Advanced Member level 4
- Joined
- Nov 29, 2009
- Messages
- 114
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,296
- Location
- goa
- Activity points
- 2,195
i tried generating a 2us square wave.
what i did is seRC0 high initially and then make it low when interrupt occurs and after exiting the ISR again set it high
so i get a 2us pulse but there is a undesired off time between two periods. Is is possible to get rid of it ?
- - - Updated - - -
The controller is PIC18F4520 at 20M crystal and compiler is MIkroC
what i did is seRC0 high initially and then make it low when interrupt occurs and after exiting the ISR again set it high
so i get a 2us pulse but there is a undesired off time between two periods. Is is possible to get rid of it ?
Code:
/*Example Source Code For PIC Timers
* THis blinks LEDs on PORTB to show interrupt rates
*
* Barton Dring
* Dring Engineering Services
* www.eng-serve.com
*
* Example only! Use any code at your own risk.
*/
// Interrupt Handler
void interrupt()
{
// Timer0 Interrupt - Freq = 500000.00 Hz - Period = 0.000002 seconds
if (INTCON.TMR0IF ==1) // timer 0 interrupt flag
{
LATC.RC0 = 0; // Toggle PORTB bit0 LED
INTCON.TMR0IF = 0; // clear the flag
INTCON.TMR0IE = 1; // reenable the interrupt
TMR0L = 250;
// reset the timer preset count
}
}
// code starts here...
void main()
{
// setup portb to show the interrupts by blibking LEDs
TRISC = 0x00; // PORT is all output...to show the interrupts
PORTC = 0; // start with all outputs low
//Timer0 Registers Prescaler= 1 - TMR0 Preset = 246 - Freq = 500000.00 Hz - Period = 0.000002 seconds
T0CON.T0CS = 0; // bit 5 TMR0 Clock Source Select bit...0 = Internal Clock (CLKO) 1 = Transition on T0CKI pin
T0CON.T0SE = 0; // bit 4 TMR0 Source Edge Select bit 0 = low/high 1 = high/low
T0CON.PSA = 1; // bit 3 Prescaler Assignment bit...0 = Prescaler is assigned to the WDT
T0CON.T0PS2 = 0; // bits 2-0 PS2:PS0: Prescaler Rate Select bits
T0CON.T0PS1 = 0;
T0CON.T0PS0 = 0;
T0CON.T08bit = 1;
TMR0L = 246; // preset for timer register
// Interrupt Registers
INTCON = 0; // clear the interrpt control register
INTCON.TMR0IE = 1; // bit5 TMR0 Overflow Interrupt Enable bit...1 = Enables the TMR0 interrupt
INTCON.TMR0IF = 0; // bit2 clear timer 0 interrupt flag
INTCON.GIE = 1;
LATC.RC0=1; // bit7 global interrupt enable
T0CON.TMR0ON=1;
while(1) //endless loop
{
LATC.RC0=1;
}
}
- - - Updated - - -
The controller is PIC18F4520 at 20M crystal and compiler is MIkroC