CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Set Timer0 and Timer1

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
jpts



Joined: 08 Mar 2017
Posts: 40

View user's profile Send private message

Set Timer0 and Timer1
PostPosted: Tue May 23, 2017 11:42 am     Reply with quote

I opened a new post for help about setting Timer0 and Timer1 of PIC16F18857. Last post you give little idea about setting PPS, but still need your help until I full understand the logic of PPS and names to link pins.

Now i am having same problem to set Timer0(16 bits) and Timer1 as a counter.
For Timer0 using PIN_A4 and for TIMER1 PIN_RC0,
normally I setup :
Code:

setup_timer_0(RTCC_EXT_L_TO_H|RTCC_DIV_1| ??? for 16 bits);     
setup_timer_1(T1_EXTERNAL|T1_DIV_BY_1); 

but its not counting external pulses coming in ....should it be set a different way for PIC16F18857 ?

Other information about project...
Code:
#include <16F18857.h>
#device ADC=10
#use delay(crystal=20000000)


//Fuses should be before UART setup etc..
#FUSES NOBROWNOUT
#FUSES NOLVP
#FUSES NOWDT
#FUSES NOPPS1WAY
#FUSES STVREN
#FUSES NOMCLR


//On this chip the UART uses PPS. This is how to setup PPS
#PIN_SELECT U1RX=PIN_C7
#PIN_SELECT U1TX=PIN_C6

#use rs232(baud=9600,parity=N,UART1,bits=8,stream=PORT1,errors)
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue May 23, 2017 12:42 pm     Reply with quote

Quote:

setup_timer_0(RTCC_EXT_L_TO_H | RTCC_DIV_1 | ??? for 16 bits);

The parameters for CCS functions are given in the .h file for the PIC.
Look in 16F18857.h and look specifically in the Timer0 section. It lists
the parameters to select 8 or 16 bit operation.
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Wed May 24, 2017 12:55 am     Reply with quote

and as a further comment, I refer to my previous post pointing out that what signals are affected by PPS is also in the include file. Both T0CK and T1CK are selectable, so:

#PIN_SELECT T0CK=PIN_A4
#PIN_SELECT T1CK=PIN_C0

will ensure these are on the pins you want.
Code:

////////////////////////////////////////////////////////////////// PIN_SELECT
// #pin_select function=pin
// Valid Pins:
//    PIN_A0,PIN_A1,PIN_A2,PIN_A3,PIN_A4,PIN_A5,PIN_A6,PIN_A7,PIN_B0,PIN_B1,
//    PIN_B2,PIN_B3,PIN_B4,PIN_B5,PIN_B6,PIN_B7,PIN_C0,PIN_C1,PIN_C2,PIN_C3,
//    PIN_C4,PIN_C5,PIN_C6,PIN_C7,PIN_E3
// Input Functions:
//    INT0,T0CK,T1CK,T1G,T3CK,T3G,T5CK,T5G,T2CK,T4CK,T6CK,CCP1,CCP2,CCP3,CCP4,
//    CCP5,SMT1WIN,SMT1SIG,SMT2WIN,SMT2SIG,CWG1IN,CWG2IN,CWG3IN,MDCARL,MDCARH,
//    MDSRC,CLCIN0,CLCIN1,CLCIN2,CLCIN3,ADCACT,SCK1IN,SCL1IN,SDI1,SDA1IN,SS1IN,
//    SCK2IN,SCL2IN,SDI2,SDA2IN,SS2IN,U1RX,U1CKIN,T0CKI,T1CKI,T3CKI,T5CKI,T2CKI,
//    T4CKI,T6CKI,CCP1IN,CCP2IN,CCP3IN,CCP4IN,CCP5IN,RX1
// Output Functions:
//    NULL,CLC1OUT,CLC2OUT,CLC3OUT,CLC4OUT,CWG1OUTA,CWG1OUTB,CWG1OUTC,CWG1OUTD,
//    CCP1OUT,CCP2OUT,CCP3OUT,CCP4OUT,CCP5OUT,PWM6OUT,PWM7OUT,U1TX,U1DT,C1OUT,
//    C2OUT,SCK1OUT,SCL1OUT,SDA1OUT,SDO1,SCK2OUT,SCL2OUT,SDA2OUT,SDO2,T0OUT,
//    NCO1OUT,CLKROUT,DSMOUT,CWG2OUTA,CWG2OUTB,CWG2OUTC,CWG2OUTD,CWG3OUTA,
//    CWG3OUTB,CWG3OUTC,CWG3OUTD,ADGRDA,ADGRDB,PWM6,PWM7,TX1,DT1,SCK1,SCL1,SDA1,
//    SCK2,SCL2,SDA2,NCO1
//

This gives, first the RP pins (so pins to which things can be mapped), then the input signals that can be mapped, followed by the output signals that can be mapped.

Now the data sheet will tell you that certain pins are the 'default' for signals. Problem is that the compiler does not always seem to 'know' this, and doesn't necessarily setup the TRIS etc. correctly. So for PPS peripherals it is safer to explicitly set all relocatable functions where you want them to be, then the compiler knows from the 'select' lines that this is where the signals are.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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