|
|
View previous topic :: View next topic |
Author |
Message |
pdswar
Joined: 18 Jul 2006 Posts: 33 Location: Maryland, USA
|
need help with PIC18F6722 ISR setup_timer_0() |
Posted: Wed Aug 16, 2006 2:04 pm |
|
|
I am using Internal Oscillator (INTRC) inside PIC 18F6722 operating at 8MHz. I want LCD_SCP signal (output from PIN F1) to oscillate at 1MHz.
#include <18F6722.h>
#device adc=10
#fuses INTRC, NOWDT, NOPUT, NOPROTECT, BROWNOUT
#use delay(clock=8000000) // Do I need this if I am using INTRC
#include <stdio.h>
#include <stdlib.h>
#int_timer0
void int_timer0_isr()
{
output_high(LCD_SCP);
output_low(LCD_SCP);
}
void main()
{
setup_oscillator(OSC_8MHZ|OSC_INTRC);
set_tris_f(0x00); // Use all pins in Port F for outputs; LCD_SCP is output from PIN_F1
output_low(LCD_SCP);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_8); // I don't know how does this line of code work
enable_interrupts(int_timer0);
enable_interrupts(global);
}
I am getting a constant low signal @ LCD_SCP (output from PIN_F1). |
|
|
Ttelmah Guest
|
|
Posted: Wed Aug 16, 2006 2:40 pm |
|
|
First, yes, you _need_ the 'use delay' statement. This is used to tell lots of other bits of code, what frequency your chip is actually running at. In fact, you should not need the oscillator setup at all. Depending on your compiler version, if the INT_RC fuse is selected, and a compatible rate in the use delay statement, the compiler will automatically setup the oscillator for you.
Second. There is no way at all, that you can get a 1MHz output using the interrupt. With a 8MHz clock, your chip is executing 2Mips. The call to the interrupt alone, involves typically 20+ instructions, and then the same again to return...
You do not need to control TRIS, unless you are using fast_io.
Your chip, is actually going to sleep, and never executing the interrupt, when it runs off the 'end' of the main code.
With a /8 prescaler, the timer will be incrementing every 32 clock cycles. The interrupt will only ocur when the timer wraps round at the end of it's count. As setup, the counter is in 16bit mode, so the interrupt (if the chip was awake), would occur after 65536*32 cycles. About 1/4 second...
You can generate a 1MHz, with the CCP module in the hardware. Trying to do it in software, will leave you with a chip that can do nothing else, and in fact to get to this rate is beyond the abilities of the chip...
For the CCP, setup timer2, to use:
setup_timer_2(T2_DIV_BY_1,1,1);
and then use one of the four CCP pins.
Best Wishes |
|
|
pdswar
Joined: 18 Jul 2006 Posts: 33 Location: Maryland, USA
|
attn: CCS Forum Moderator |
Posted: Fri Aug 18, 2006 8:25 am |
|
|
I am trying to get 40kHz output pulse while my Internal Oscillator of PIC18F6722 is running at 8MHz. I can change Internal Oscillator frequency if that is necessary.
The following thread discusses similar issue but apparently filename or the code has been removed by the moderator
http://www.ccsinfo.com/forum/viewtopic.php?t=26179&highlight=rtcc
I am a licensed CCS C Compiler user. Can you please tell me which example file were these thread users were referring to? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Aug 18, 2006 10:25 am |
|
|
It was probably this one:
c:\program files\picc\examples\ex_patg.c |
|
|
pdswar
Joined: 18 Jul 2006 Posts: 33 Location: Maryland, USA
|
timing problem |
Posted: Sat Aug 19, 2006 4:48 pm |
|
|
Ttelmah and PCM Programmer, thank you for replying. Your information are always helpful. Please bear with me since I am a beginner to embedded programming.
This is what I am trying to do:
A timer interrupt should be used for refreshing the display.
---Start of interrupt routine
---If it is the first line of the display set the LCD_FLM signal to high
---Shift the data for the corresponding row of the displays
40 LCD_SCP clock signal; 40 LCD_DIN data signal
---Toggle the LCD_LP signal (min. hold time 200ns) after data is shifted
---Set the LCD_FLM signal to low
---Increment line number of the display. If equal to 25 set it to 1.
---End of interrupt routine
//Recommended LP-to-LP timing =1 ms
//LCD_SCP frequency = 40kHz
#include "18F6722.h"
#device adc=10
#fuses INTRC, NOWDT
#use delay(clock=8000000) // Set clock to 8MHz
int row,col,bits;
int32 frame[24]={
//plus sign
0b00000000000001111000000000000000,//0
0b00000000000001111000000000000000,//1
0b00000000000001111000000000000000,//2
0b00000000000001111000000000000000,//3
0b00000000000001111000000000000000,//4
0b00000000000001111000000000000000,//5
0b00000000000001111000000000000000,//6
0b00000000000001111000000000000000,//7
0b00000000000001111000000000000000,//8
0b00000000000001111000000000000000,//9
0b11111111111111111111111111111111,//10
0b11111111111111111111111111111111,//11
0b11111111111111111111111111111111,//12
0b00000000000001111000000000000000,//13
0b00000000000001111000000000000000,//14
0b00000000000001111000000000000000,//15
0b00000000000001111000000000000000,//16
0b00000000000001111000000000000000,//17
0b00000000000001111000000000000000,//18
0b00000000000001111000000000000000,//19
0b00000000000001111000000000000000,//20
0b00000000000001111000000000000000,//21
0b00000000000001111000000000000000,//22
0b00000000000001111000000000000000 //23
};
//Need LCD_SCP to oscillate at 40kHz; 40 LCD_SCP pulses between 1 ms
//Using TIMER2
#int_TIMER2
void TIMER2_isr()
{
output_high(LCD_FLM);
for(row=0;row<24;row++)
{
for(col=0;col<40;col++)
{
output_high(LCD_SCP);
//LCD_DIN goes here
if(col<32)
{
if(bit_test(frame[row],(31-col))) //LSB checked first
output_high(LCD_DIN);
else
output_low(LCD_DIN);
}
output_low(LCD_SCP);
}
output_high(LCD_LP); //LP-to-LP timing =1 ms
delay_us(25); //LP signal min. high hold time = 200ns = 20us
output_low(LCD_LP);
}
output_low(LCD_FLM);
delay_us(1500);
}
void main()
{
//set_tris_f(0x00);
//Initialization
output_low(LCD_SCP);
output_low(LCD_DIN);
output_low(LCD_LP);
output_low(LCD_FLM);
//Setup Interrupt
setup_timer_2(T2_DIV_BY_1,12.5,1); //12.5 uSec ON and 12.5 uSec OFF
enable_interrupts(INT_TIMER2);
enable_interrupts(global);
while(1) // does nothing; let ISRs do the work
{
}
}
My timing requirements for NKK Smartswitch are satisfied for LCD_SCP, LCD_LP and LCD_FLM if I don't send LCD_DIN signal.
As soon as I send the LCD_DIN signal, the LCD_SCP signal gets messed up (non-uniform high-hold-time and low-hold-time)
Is there a better way to send LCD_DIN signal? |
|
|
pdswar
Joined: 18 Jul 2006 Posts: 33 Location: Maryland, USA
|
|
Posted: Sat Aug 19, 2006 4:54 pm |
|
|
I tried to send LCD_DIN using RTCC module. I could not set it up so that LCD_DIN data would synchronize with LCD_SCP clock.
//Send LCD_DIN at 40kHz
//Using RTCC (aka TIMER0)
#int_RTCC
void rtcc_isr()
{
bits=0;
while(bits<32) //No. of bits in int32 data=32
{
if(bit_test(tagframe1[0],(31-bits))) //decrements the bit index; LSB checked first
output_high(LCD_DIN);
else
output_low(LCD_DIN);
bits++;
}
}
}
............
set_timer0(206); // 256 - (.000025/(4/8000000))
setup_counters(RTCC_INTERNAL, RTCC_DIV_1 | RTCC_8_BIT);
enable_interrupts(INT_RTCC);
........... |
|
|
pdswar
Joined: 18 Jul 2006 Posts: 33 Location: Maryland, USA
|
|
Posted: Wed Aug 23, 2006 9:16 am |
|
|
Thanks everyone,
My code is working now. |
|
|
|
|
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
|