Vasil Borisov

Lpc1115 reading a Hall sensor

Discussion created by Vasil Borisov on Jan 19, 2018
Latest reply on Jan 22, 2018 by Kerry Zhou

Hello guys,

I am new to embedded programming and I want to ask some questions. I have a project where I need to measure time interval between two rising edges (formed by a Hall sensor). I plan to use a counter with a capture so I can measure the time interval between 2 rising edges and display that through a UART serial connection. For the time being I am trying to just to read the value of the TC at moment when a capture event occurs on the pin ( CAP PIN1_5 - for TMR32B0). The strange thing is that when I try to flash this code into the memory my UART stops sending, while I am using debug session and USB cable everything is OK. My point is that I need to flash that into the memory so I can connect the Hall sensor to the capture pin and supply the board with an external power supply in order them to share a common ground.

Here is my code:


Name : TestLPC1115.c
Author : $(author)
Version :
Copyright : $(copyright)
Description : main definition

#ifdef __USE_CMSIS
#include "LPC11xx.h"

#include <stdlib.h>
#include <stdint.h>
#include <stdio.h>
#include <cr_section_macros.h>
#include "delay.h"
#include "uart.h"
#include "gpio.h"
#include "timer32.h"

int main(void)
float count_value;
char string[20];

LPC_IOCON->PIO1_5 &= ~0x07;                         // Timer0_32 I/O config */
LPC_IOCON->PIO1_5 |= 0x02;                              // Timer0_32 CAP0 */
LPC_IOCON->PIO1_5 = (0<<3) | (0<<4);          // disable pull-up and pull-down resistors

LPC_SYSCON->SYSAHBCLKCTRL |= (1<<10); // enable clock for timer1

//configure counter
LPC_TMR32B0->TCR =0x2; //counter disable
LPC_SYSCON->SYSAHBCLKCTRL |= (1<<9); // enable clock for timer0
LPC_TMR32B0->CTCR =0x1; //counter mode,increments on rising edges
LPC_TMR32B0->PR =0x0; //set prescaler
LPC_TMR32B0->TCR =0x1; //counter enable


count_value = LPC_TMR32B0->TC;
sprintf(string, "Value = %f \r\n", count_value);