View previous topic :: View next topic |
Author |
Message |
noman yousaf
Joined: 07 Jan 2016 Posts: 17 Location: pakistan
|
timer output on ports problem |
Posted: Thu Jan 07, 2016 9:57 am |
|
|
I want to get the value 16 bit timer/counter1 (as counter) on port b and c.
I set the timer1 as follows. Now how can i get the values of timer on ports?
Code: |
void main()
{
TMR = 0X26;
SETUP_TIMER_1(RTCC_EXT_H_TO_L);
SET_TIMER1(TMR);
while(1)
{
;/// here how can i split 8 bits of 16 bit timer and get data on ports?
}
} |
|
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9225 Location: Greensville,Ontario
|
|
Posted: Thu Jan 07, 2016 10:45 am |
|
|
simply put, read the manuals !
A quick read of the datasheet for your PIC will show the 16bit timer to be stored in 2 sucessive registers( memory locations).
Now, read the CCS manual ( press F11 while in a project), search for timer, and see how to access those registers.
There's probably an example or two as CCS does provide a LOT of fine examples covering most of the PICs operations....
These days you should use the 'get env' function to be sure the compiler gets the correct registers though. Again, consult the CCS manual for proper use.
BTW: To acquire the data and display should take 8 lines of code.
Also, be careful about the 'order' though other wise when you read the LEDs on the ports they won't look correct !!
The more you read the better the programmer you will be.
Jay |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Jan 07, 2016 5:26 pm |
|
|
Quote: |
SETUP_TIMER_1(RTCC_EXT_H_TO_L);
|
This is wrong. The value in bold is not a correct parameter for the
setup_timer_1() function. Look in the .H file for your PIC in the
SETUP_TIMER_1 section, to see the list of correct parameters.
Quote: | I want to get the value 16 bit timer/counter1 (as counter). |
Use the get_timer1() function to read the 16-bit Timer1 value into an
int16 variable.
Quote: | how can i split 8 bits of 16 bit timer and get data on ports? |
Use the make8() function to get the high or low byte from the 16-bit
variable.
Quote: | I want to get the value on port b and c. |
Use the output_b() and output_c() functions.
For more information, read the CCS manual:
http://www.ccsinfo.com/downloads/ccs_c_manual.pdf |
|
|
noman yousaf
Joined: 07 Jan 2016 Posts: 17 Location: pakistan
|
|
Posted: Fri Jan 08, 2016 7:47 pm |
|
|
PCM programmer wrote: | Quote: |
SETUP_TIMER_1(RTCC_EXT_H_TO_L);
|
This is wrong. The value in bold is not a correct parameter for the
setup_timer_1() function. Look in the .H file for your PIC in the
SETUP_TIMER_1 section, to see the list of correct parameters.
Quote: | I want to get the value 16 bit timer/counter1 (as counter). |
Use the get_timer1() function to read the 16-bit Timer1 value into an
int16 variable.
Quote: | how can i split 8 bits of 16 bit timer and get data on ports? |
Use the make8() function to get the high or low byte from the 16-bit
variable.
Quote: | I want to get the value on port b and c. |
Use the output_b() and output_c() functions.
For more information, read the CCS manual:
http://www.ccsinfo.com/downloads/ccs_c_manual.pdf |
thanks sir. you were right. my timer1 setting was not correct.
i did it. |
|
|
noman yousaf
Joined: 07 Jan 2016 Posts: 17 Location: pakistan
|
|
Posted: Fri Jan 08, 2016 7:54 pm |
|
|
i wrote this program
Code: |
//this software runs the timer1 as counter and put the 16 bit value
// to portb and portd
#include <18F458.h>
#USE DELAY (crystal=4MHz)
UNSIGNED INT TMR;
unsigned int16 timer1_val,tmr1;
void main()
{
TMR1 = 0X12f4; // timer1 starts from this value
SETUP_TIMER_1(T1_EXTERNAL); // set timer1 as external pulse counter
SET_TIMER1(TMR1); // put "12f4" value in timer1 to start from
WHILE(1)
{
timer1_val=GET_TIMER1(); //put the value ofmtimer 1 in "timer_val"
tmr=make8(timer1_val,0); // split 8 bit value (lsb) and mov it to "tmr"
output_b(tmr); // feed the value to portb
tmr=make8(timer1_val,1); // split 8 bit value (msb) and mov it to "tmr"
output_d(tmr);// feed the value to portd
}
}
|
|
|
|
|