New and Confused about HCS08 Timers.  Please Help...

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

New and Confused about HCS08 Timers.  Please Help...

3,595 Views
Jporter
Contributor I
I am reading data from serial port. I would like to time out and reset my pointers, etc. if I don't receive a character in 1ms. On other microcontrollers I use a timer/counter with an overflow interrupt. Every time i receive a character I reset the counter which delays the overflow interrupt. However if I get an overflow interrupt then I know I have timed out and I can reset my buffer. This is very basic and supported by almost all controllers.

I am new to HCS08 and it seems that the timers have a steep learning curve. So I started with processor expert to get a sample code I can start from. There are so many options for timers and counters but none of them offer the choices of overflow interrupt and reset.

I am using a GT60 HCS08 with 16Mhz clock and also using SMAC.

I would greatly appreciate anyone pointing me to some code snippet or processor expert bean choices that shows me how to do this on the HCS08.

Jason
Labels (1)
0 Kudos
9 Replies

574 Views
EvanYin
Contributor I
There's a timer in file "uart.c"
 
add the following code into fuction "void SCI_Init(void){}"
void SCI_Init(void)
{
//other code.....
TPM1SC = 0x48;
TPM1MODH = ox3E; //0x3E80 means the 16MHz system will enter isr every 1ms
TPM1MODL = ox80;
}
//here is the isr
interrupt void UART_TIMER_ISR(void)
{
 TPM1SC &= 0x7F; // Read, Clear bit 7, Write
 UartRxTimer++;  //  
 generalTimer++; // 
 //the system will be entered every 1ms, just add your own code here.
 //......
}
 
 
here's my mail: yanzexuan@gmail.com
 
because it's a bad network as I'm in china
 
Evan
0 Kudos

574 Views
Jporter
Contributor I
Hi Evan,
Thanks very much. This looks clean and simple. I assume I have to add the UART_TIMER_ISR to the vectors.c in the interrupt position 5. Do I need any code to initialize or enable this interrupt? How would I disable this interrupt?
Thanks again and best regards,
Jason
0 Kudos

574 Views
joerg
Contributor II
Hi Jporter

You can also have a look at EBS08, where i use the TIM for generating the TIC's (with the MOD register or as Output capture). IF you want i have also modules for the SCI (for command lines delimited ie. LF and with a ring-buffer).

Saluti Joerg
0 Kudos

574 Views
rocco
Senior Contributor II
Hi, Jason:

Do you need a timer at all? Will "Idle-line detect" do the job?

You did not mention what baud rate you are using, but 1 millisecond is about one character time at 9600 baud.

If your purpose is to detect when the other end of the line has finished transmitting, the SCI may be able to do that for you. The Idle-line detect feature in the SCI can give you an interrupt when the line has been idle for one whole character period. No timer necessary.

It is one of the reasons that the manual is so darn big . . . :smileywink:
0 Kudos

574 Views
Jporter
Contributor I
Rocco,
Thanks for your post. I actually got the overflow interrupt working.
I actually reset the counter every time character so the only time I get an overflow interrupt is when the stream is completed.
However, I was not aware of the idle-line interrupt as it appears to be a cooler way of doing it.
Something to try next time.
Thanks again,
Jason
0 Kudos

574 Views
ProcessorExpert
Senior Contributor III
Dear Customer,
In your case it is suitable and easy solution to use the TimerInt bean. Set 1ms for timer channel. After receiving character you can disable and enable this bean by its methods that causes reset counter and delays the overflow interrupt as you need.
I hope this help you.
Best Regards,
Jan Pospisilik, Processor Expert Support
 
0 Kudos

574 Views
Jporter
Contributor I
Hi Jan,
This was a great suggestion as I managed to get the interrupt working with processor expert. However I am having a hell of a time just cutting the interrupt portion and pasting it to my working code which was originally derived from the BeeKit. I think I am getting close but there are still many processor expert macros that I have to get rid of tp have a clean compile.
Jason
0 Kudos

574 Views
bigmac
Specialist III
Hello Jason,
 
Your timing is probably most easily handled using one of the timer channels set up for output compare mode (interrupt only - with no pin output required).  Make sure the timer prescale value is set so that the timer overflow period is more than 1 ms.  You will also need to calculate how many timer clock periods represent  the 1 ms period.
 
After receiving each serial character -
  1. Read the value in the timer counter register.
  2. Add to this the number of timer clock periods for 1ms delay - don't worry about any overflow in the calculation.
  3. Write this new word value to the timer channel register (of the channel you are using).
  4. Clear the timer channel flag.
  5. Enable the timer interrupt for the channel.
Should you then get a timer channel interrupt, the ISR for the channel should -
  1. Clear your pointers, buffers, etc.
  2. Disable further timer channel interrupts.
The timer is continuously incrementing during this process - it is not necessary to ever stop or reset the timer.  The timer overflow interrupt is not used.
 
Regards,
Mac
 
0 Kudos

574 Views
Jporter
Contributor I
Hi Mac,
Thank you very much for your post. This sounds like it would work exactly for what I need. I am, however, very new to HC08 and very intimidated by hundreds of pages of documentation on the processor and the TPU. I would be very grateful if you can point me to some example code that shows me how to set various registers and prescalar values. I am ready to give up on Processor Expert on which I have spent many hours. So at this stage a sample timer code or tutorial in conjunction with your suggestions in your post will give me jump start I need.
Thanks again,
Jason
0 Kudos