|
|
View previous topic :: View next topic |
Author |
Message |
srikrishna
Joined: 06 Sep 2017 Posts: 82
|
How timer value updated by get_ticks() |
Posted: Tue Oct 24, 2017 1:18 am |
|
|
Hello i wanted to print timer value each time when it is updated .The get_ticks()
function updated the timer value each time but how i can print the timer value??
I have write a code for this
Code: | #include <18f2550.h>
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
#FUSES HS,NOWDT
#USE delay(clock=20M)
#USE TIMER(TIMER=1,TICK=1ms,BITS=16,NOISR)
void main(void)
{
while(1)
{
unsigned int16 current_tick;
current_tick = get_ticks();
delay_us(15);
}
} |
Last edited by srikrishna on Tue Oct 24, 2017 3:53 pm; edited 1 time in total |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9243 Location: Greensville,Ontario
|
|
Posted: Tue Oct 24, 2017 4:51 am |
|
|
1st we need to know WHERE you want to 'print' the value. Typically that's either sending the data to a PC serially, displaying on an LCD module wired to the PIC or 'old school', turning on a set of LEDs to be the '1's and '0's of the data.
If serial to a PC, read the #USE RS232(...options...) in the manual. Pressing F11 while your project is open, will access the CCS C manual! It's well laid out, easy to read.
If using an LCD module, CCS does supply a driver though I prefer the 'flex_lcd' driver, it's in the 'code library' on this site.
If using LEDs, you'll need 2 x 8bit ports and 3-4 lines of code. Be sure to use appropriate current limiting resistors.
You should also have a good look at the dozens and dozens of example programs CCS kindly supplies in their 'examples' folder. You'll find working code for almost anything you need !!
While I have been using PICs for the past 2+ decades, I am not a trained C programmer, so my programs won't past the 'correct code cops' and you soon find out there are several ways to get the results you want.
The first program you need to code is a '1Hz LED' program. It 'simply' flashes an LED about once per second. Get that working and you know that the PIC is powered properly and wired correctly, that the compiler works and you can download code into the PIC.
Once this works THEN build upon your new found knowledge and cut your next program !!
Jay
Jay |
|
|
srikrishna
Joined: 06 Sep 2017 Posts: 82
|
|
Posted: Tue Oct 24, 2017 4:12 pm |
|
|
When,
T1SYNC# = 0,
Timer1 operates as a synchronous counter because the input pulses to TMR1 travel through the synchronization block. This block samples the input signal and synchronizes it with the microcontroller’s internal
clock. The resulting signal has edges that are in phase with the main clock of the PIC. This synchronized signal drives the 16-bit counter TMR1 that is made by the TMR1L and TMR1H registers.When Timer1 is configured to work as a timer bysetting
TMR1CS = 0,
the T1SYNC# bit is ignored
While simulating at oshonsoft pic18f software i have got the following results
Last edited by srikrishna on Wed Oct 25, 2017 2:16 am; edited 1 time in total |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9243 Location: Greensville,Ontario
|
|
Posted: Tue Oct 24, 2017 7:28 pm |
|
|
OK, I do NOT use that 'simulator' so I cannot verify that it actually works 100% to 'simulate' the PIC . So far after 2+ decades ,I've yet to find any simulator that does simulate a PIC properly.
The screen shots you present lack 'context'. I do not know what they are, what they represent,what 'program' is 'running' but most importantly, I have ZERO faith that the 'simulator' actually simulates a PIC microcode.
Your original post was about 'printing' out the value of a timer. 'Printing' involves the display of some data, that's why I asked 'how' you want to see the data. I was assuming you have the PIC on a PCB and usually you send data to either a PC terminal program, using serial I/O( aka RS-232) or an LCD module using a 'driver', typically in 4 bit mode( saves 1 pin) or 'old school', use 16 LEDs to show the data in binary format. |
|
|
guy
Joined: 21 Oct 2005 Posts: 297
|
|
Posted: Wed Oct 25, 2017 7:09 am |
|
|
how about
Code: | printf("timer1 %Lu",get_timer1()) | ? |
|
|
|
|
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
|