hamedtahamtan
Newbie level 1
hello
i coding cmsis for lpc1768
ther is som days that i try to run counter but i have some problems with it
at first i teke my code here and then i will describe my problem
i have 2 basic problem .
the first 1 is that when i init timer/counter i cant apoint a pin for input timer pulse with cmsis code and i forced to change then ctcr register manuly. like theis
and it is work properly , but i want to do thes by smsis code )becuse this is a weakness in my coding .
the second one is that when i init timer as counter i cant set the prescaler AND THis lines dosnt work
before answering to this , i shuld apologize you becuse of my weak english writing:bang:.
thanke you!!
i coding cmsis for lpc1768
ther is som days that i try to run counter but i have some problems with it
at first i teke my code here and then i will describe my problem
Code:
// created by neamatollah tahamtan
#include "lpc17xx_gpio.h"
#include "lpc17xx_adc.h"
#include "lpc17xx_pinsel.h"
#include "lpc17xx_libcfg_default.h"
#include <stdio.h>
#include "lpc17xx_timer.h"
void delay (uint32_t Time)
{
uint32_t i;
i = 0;
while (Time--) {
for (i = 0; i < 5000; i++);
}
}
// ****************************************************
int main (void)
{
PINSEL_CFG_Type PinCfg;
TIM_TIMERCFG_Type TIM_ConfigStruct;
TIM_CAPTURECFG_Type TIM_CaptureConfigStruct;
// ---------------- Configuration ---------------
PinCfg.Funcnum = 3;
PinCfg.OpenDrain = 0;
PinCfg.Pinmode = 0;
PinCfg.Portnum = 1;
PinCfg.Pinnum = 27;
PINSEL_ConfigPin(&PinCfg);
// ---------------------------------------------------
// Initialize timer 0, prescale count time of 100uS
TIM_ConfigStruct.PrescaleOption = TIM_PRESCALE_TICKVAL;
//TIM_ConfigStruct.PrescaleOption = TIM_PRESCALE_USVAL;
TIM_ConfigStruct.PrescaleValue = 2;
TIM_Init(LPC_TIM0, TIM_COUNTER_RISING_MODE,&TIM_ConfigStruct);
//---------------------------------------------------------------
// use channel 0, CAPn.0
TIM_CaptureConfigStruct.CaptureChannel = 1;
// Enable capture on CAPn.0 rising edge
TIM_CaptureConfigStruct.RisingEdge = ENABLE;
// Enable capture on CAPn.0 falling edge
TIM_CaptureConfigStruct.FallingEdge = DISABLE;
// Generate capture interrupt
TIM_CaptureConfigStruct.IntOnCaption = DISABLE;
// Set configuration for Tim_config and Tim_MatchConfig
TIM_ConfigCapture(LPC_TIM0, &TIM_CaptureConfigStruct);
TIM_ResetCounter(LPC_TIM0);
TIM_Cmd(LPC_TIM0,ENABLE);
LPC_TIM0->CTCR=5;
while (1)
{
}
}
i have 2 basic problem .
the first 1 is that when i init timer/counter i cant apoint a pin for input timer pulse with cmsis code and i forced to change then ctcr register manuly. like theis
Code:
LPC_TIM0->CTCR=5;
the second one is that when i init timer as counter i cant set the prescaler AND THis lines dosnt work
Code:
// Initialize timer 0, prescale count time of 100uS
TIM_ConfigStruct.PrescaleOption = TIM_PRESCALE_TICKVAL;
//TIM_ConfigStruct.PrescaleOption = TIM_PRESCALE_USVAL;
TIM_ConfigStruct.PrescaleValue = 2;
before answering to this , i shuld apologize you becuse of my weak english writing:bang:.
thanke you!!