Lpc1115 reading a Hall sensor

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Lpc1115 reading a Hall sensor

743 Views
vasilborisov
Contributor I

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"
#endif

#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];
UARTInit(9600);

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

while(1){

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

}
}

Labels (1)
Tags (2)
3 Replies

593 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Vasil Borisov,

    Two points you need to note:

1. When you program the chip, you need to download the code to the flash, not the RAM.

    After you download the code to the chip flash, both debug and without debug, the code can work.

   But if you download the code to the RAM, after power off and power on the board again, the code will be disappear.

   So, please configure your project, download the code to the flash.

2. Note the PIO0_1 pin when you do the reset

pastedImage_1.png

After you download the code to the chip, without debugging, before you do the reset, you must make sure PIO_1 is high, otherwise, you code will enter in the ISP mode.

So, just keep the PIO0_1 as higher.

Wish it helps you!


Have a great day,
Kerry

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

593 Views
vasilborisov
Contributor I

Hello Kerry,

thank you for your detailed reply, I am going to try that and post here if I had any success :smileyhappy:

0 Kudos

593 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Vasil Borisov,

You are welcome, waiting for your updated information.


Have a great day,
Kerry

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos