Content originally posted in LPCWare by assembled on Fri Mar 22 10:58:27 MST 2013 Hi everyone, I am having trouble with Timer0 Capture0. I am using LPC1114/301, IDE version LPCXpresso v4.2.3.
Setup: optical interrupter output is connected to PIO1_5, signal is good, frequeny varies from few Hz to 750Hz.
I took the PWM example and modified it to:
int main (void) {
init_timer32(0, 0xFFFFFFFF);
enable_timer32(0);
LPC_SYSCON->SYSAHBCLKCTRL |= (1<<6);
GPIOSetDir( 2, 5, 1 );
while (1) /* Loop forever */
{
/* I/O configuration and LED setting pending. */
setMatch_timer16PWM (1, 1, 900-timer32_0_capture);
if (GetGPIOBit(1,5))
SetGPIOBit(2,5);
else
ClrGPIOBit(2,5);
}
}
IRQ:
void TIMER32_0_IRQHandler(void)
{
uint32_t temp;
if ( LPC_TMR32B0->IR & 0x01 )
{
LPC_TMR32B0->IR = 1; /* clear interrupt flag */
timer32_0_counter++;
}
if ( LPC_TMR32B0->IR & (0x1<<4) ) //jei CAP
{
LPC_TMR32B0->TC = 0; //Reset timer
if ( LPC_TMR32B0->CR0 > 0x75300)
{
if (timer32_0_capture < 1999)
{
timer32_0_capture++;
}
}
else
{
temp = LPC_TMR32B0->CR0;
if (timer32_0_capture > 1)
timer32_0_capture--;
}
LPC_TMR32B0->IR = 0x1<<4; /* clear interrupt flag */
}
return;
}
Im main I am only using timer32_0_capture for PWM PW and putting P1.5 state to P2.5 just to make sure my signal is OK.
In IRQ I compare CR0 to a fixed value and increasing or decreasing timer32_0_capture accordingly. Now for problems: 1. CR0 value is "random". You can see that I assign it to variable [B]temp[/B] and I occasionally get temp values of 1, 11, etc. It does not depend on input frequency. My timer32_0_capture is just moving around 1..2 whatever the input signal interval.
I suppose I am just missing some childish mistake but I am unable to find it.
Content originally posted in LPCWare by assembled on Mon Mar 25 07:14:45 MST 2013 Problem solved by enabling Hysteresis on pin. It seems that quite slow pulse transition times of encoder caused miscaptures.
Content originally posted in LPCWare by assembled on Sat Mar 23 04:04:52 MST 2013 Thank you for your reply. As I said, my program is based on pwm demo code and standard timer32.c:
/******************************************************************************
** Function name: init_timer
**
** Descriptions: Initialize timer, set timer interval, reset timer,
** install timer interrupt handler
**
** parameters: timer number and timer interval
** Returned value: None
**
******************************************************************************/
void init_timer32(uint8_t timer_num, uint32_t TimerInterval)
{
if ( timer_num == 0 )
{
/* Some of the I/O pins need to be carefully planned if
you use below module because JTAG and TIMER CAP/MAT pins are muxed. */
LPC_SYSCON->SYSAHBCLKCTRL |= (1<<9);
LPC_IOCON->PIO1_5 &= ~0x07; /* Timer0_32 I/O config */
LPC_IOCON->PIO1_5 |= 0x02; /* Timer0_32 CAP0 */
LPC_IOCON->PIO1_6 &= ~0x07;
LPC_IOCON->PIO1_6 |= 0x02; /* Timer0_32 MAT0 */
LPC_IOCON->PIO1_7 &= ~0x07;
LPC_IOCON->PIO1_7 |= 0x02; /* Timer0_32 MAT1 */
LPC_IOCON->PIO0_1 &= ~0x07;
LPC_IOCON->PIO0_1 |= 0x02; /* Timer0_32 MAT2 */
#ifdef __JTAG_DISABLED
LPC_IOCON->JTAG_TDI_PIO0_11 &= ~0x07;
LPC_IOCON->JTAG_TDI_PIO0_11 |= 0x03; /* Timer0_32 MAT3 */
#endif
#if CONFIG_TIMER32_DEFAULT_TIMER32_0_IRQHANDLER==1
timer32_0_counter = 0;
timer32_0_capture = 0;
#endif //TIMER32_0_DEFAULT_HANDLER
LPC_TMR32B0->MR0 = TimerInterval;
#if TIMER_MATCH
LPC_TMR32B0->EMR &= ~(0xFF<<4);
LPC_TMR32B0->EMR |= ((0x3<<4)|(0x3<<6)|(0x3<<8)|(0x3<<10)); /* MR0/1/2/3 Toggle */
#else
/* Capture 0 on rising edge, interrupt enable. */
LPC_TMR32B0->CCR = (0x1<<1)|(0x1<<2);
#endif
LPC_TMR32B0->MCR = 3; /* Interrupt and Reset on MR0 */
#if CONFIG_TIMER32_DEFAULT_TIMER32_0_IRQHANDLER==1
/* Enable the TIMER0 Interrupt */
NVIC_EnableIRQ(TIMER_32_0_IRQn);
#endif
}
else if ( timer_num == 1 )
{
/* Some of the I/O pins need to be clearfully planned if
you use below module because JTAG and TIMER CAP/MAT pins are muxed. */
LPC_SYSCON->SYSAHBCLKCTRL |= (1<<10);
#ifdef __JTAG_DISABLED
LPC_IOCON->JTAG_TMS_PIO1_0 &= ~0x07; /* Timer1_32 I/O config */
LPC_IOCON->JTAG_TMS_PIO1_0 |= 0x03; /* Timer1_32 CAP0 */
LPC_IOCON->JTAG_TDO_PIO1_1 &= ~0x07;
LPC_IOCON->JTAG_TDO_PIO1_1 |= 0x03; /* Timer1_32 MAT0 */
LPC_IOCON->JTAG_nTRST_PIO1_2 &= ~0x07;
LPC_IOCON->JTAG_nTRST_PIO1_2 |= 0x03; /* Timer1_32 MAT1 */
LPC_IOCON->ARM_SWDIO_PIO1_3 &= ~0x07;
LPC_IOCON->ARM_SWDIO_PIO1_3 |= 0x03; /* Timer1_32 MAT2 */
#endif
LPC_IOCON->PIO1_4 &= ~0x07;
LPC_IOCON->PIO1_4 |= 0x02; /* Timer0_32 MAT3 */
#if CONFIG_TIMER32_DEFAULT_TIMER32_1_IRQHANDLER==1
timer32_1_counter = 0;
timer32_1_capture = 0;
#endif //TIMER32_1_DEFAULT_HANDLER
LPC_TMR32B1->MR0 = TimerInterval;
#if TIMER_MATCH
LPC_TMR32B1->EMR &= ~(0xFF<<4);
LPC_TMR32B1->EMR |= ((0x3<<4)|(0x3<<6)|(0x3<<8)|(0x3<<10)); /* MR0/1/2 Toggle */
#else
/* Capture 0 on rising edge, interrupt enable. */
LPC_TMR32B1->CCR = (0x1<<0)|(0x1<<2);
#endif
LPC_TMR32B1->MCR = 3; /* Interrupt and Reset on MR0 */
#if CONFIG_TIMER32_DEFAULT_TIMER32_1_IRQHANDLER==1
/* Enable the TIMER1 Interrupt */
NVIC_EnableIRQ(TIMER_32_1_IRQn);
#endif
}
return;
}
Content originally posted in LPCWare by gbm on Sat Mar 23 00:08:57 MST 2013 It's not possible to guess what's wrong with your code without seeing it. Post your timer setup routines.
0
Kudos
Reply
'
var data = div.getElementsByClassName("video-js");
var script = document.createElement('script');
script.src = "https://players.brightcove.net/" + data_account + "/" + data_palyer + "_default/index.min.js";
for(var i=0;i< data.length;i++){
videodata.push(data[i]);
}
}
}
for(var i=0;i< videodata.length;i++){
document.getElementsByClassName('lia-vid-container')[i].innerHTML = videodata[i].outerHTML;
document.body.appendChild(script);
}
}
catch(e){
}
/* Re compile html */
$compile(rootElement.querySelectorAll('div.lia-message-body-content')[0])($scope);
}
if (code_l.toLowerCase() != newBody.getAttribute("slang").toLowerCase()) {
/* Adding Translation flag */
var tr_obj = $filter('filter')($scope.sourceLangList, function (obj_l) {
return obj_l.code.toLowerCase() === newBody.getAttribute("slang").toLowerCase()
});
if (tr_obj.length > 0) {
tr_text = "This content was translated from lilicon-trans-text using AI-assisted tools.".replace(/lilicon-trans-text/g, tr_obj[0].title);
tr_text +='View original';
try {
if ($scope.wootMessages[$rootScope.profLang] != undefined) {
tr_text = $scope.wootMessages[$rootScope.profLang].replace(/lilicon-trans-text/g, tr_obj[0].title);
tr_text +='View original';
}
} catch (e) {
}
} else {
//tr_text = "This message was translated for your convenience!";
tr_text = "lilicon-trans.your.convenience";
}
try {
if (!document.getElementById("tr-msz-" + value)) {
var tr_para = document.createElement("P");
tr_para.setAttribute("id", "tr-msz-" + value);
tr_para.setAttribute("class", "tr-msz");
tr_para.style.textAlign = 'justify';
var tr_fTag = document.createElement("IMG");
tr_fTag.setAttribute("class", "tFlag");
tr_fTag.setAttribute("alt", "Translate icon");
// tr_fTag.setAttribute("title", "Disclaimer for Translate icon");
tr_fTag.setAttribute("src", "/html/assets/translate-icon.svg");
tr_para.appendChild(tr_fTag);
var container = document.createElement('span');
container.innerHTML = tr_text;
//var tr_textNode = document.createTextNode(container);
tr_para.appendChild(container);
/* Woot message only for multi source */
if(rootElement.querySelector(".lia-message-body-content").previousElementSibling != null && rootElement.querySelector(".lia-message-body-content").previousElementSibling.getAttributeNames().includes("data-generation-timestamp")){
rootElement.querySelector(".lia-message-body-content").previousElementSibling.remove()
}
if(rootElement.querySelector(".lia-quilt-forum-message")){
rootElement.querySelector(".lia-quilt-forum-message .lia-message-body").insertBefore(tr_para,rootElement.querySelector(".lia-message-body-content"));
} else if(rootElement.querySelector(".lia-message-view-blog-topic-message")) {
rootElement.querySelector(".lia-message-view-blog-topic-message .lia-message-body").insertBefore(tr_para,rootElement.querySelector(".lia-message-body-content"));
} else if(rootElement.querySelector(".lia-quilt-blog-reply-message")){
rootElement.querySelector(".lia-quilt-blog-reply-message .lia-message-body").insertBefore(tr_para,rootElement.querySelector(".lia-message-body-content"));
} else if(rootElement.querySelector(".lia-quilt-tkb-message")){
rootElement.querySelectorAll(".lia-quilt-tkb-message .lia-message-body")[0].insertBefore(tr_para,rootElement.querySelector(".lia-message-body-content"));
} else if(rootElement.querySelector(".lia-quilt-tkb-reply-message")){
rootElement.querySelectorAll(".lia-quilt-tkb-reply-message .lia-message-body")[0].insertBefore(tr_para,rootElement.querySelector(".lia-message-body-content"));
} else if(rootElement.querySelector(".lia-quilt-idea-message")){
rootElement.querySelector(".lia-quilt-idea-message .lia-message-body").insertBefore(tr_para,rootElement.querySelector(".lia-message-body-content"));
} else if(rootElement.querySelector(".lia-quilt-idea-reply-message")){
rootElement.querySelector(".lia-quilt-idea-reply-message .lia-message-body").insertBefore(tr_para,rootElement.querySelector(".lia-message-body-content"));
} else if(rootElement.querySelector('.lia-quilt-occasion-message')){
rootElement.querySelector('.lia-quilt-occasion-message .lia-message-body').insertBefore(tr_para,rootElement.querySelector(".lia-message-body-content"));
}
else {
if (rootElement.querySelectorAll('div.lia-quilt-row-footer').length > 0) {
rootElement.querySelectorAll('div.lia-quilt-row-footer')[0].appendChild(tr_para);
} else {
rootElement.querySelectorAll('div.lia-quilt-column-message-footer')[0].appendChild(tr_para);
}
}
}
} catch (e) {
}
}
} else {
/* Do not display button for same language */
// syncList.remove(value);
var index = $scope.syncList.indexOf(value);
if (index > -1) {
$scope.syncList.splice(index, 1);
}
}
}
}
}
}
/*if(mszList_l.length <= 0){
setTimeout(()=>{
var mszListl = [];
angular.forEach(document.querySelectorAll("[class*='lia-js-data-messageUid']"), function(element) {
var mszId = element.getAttribute("data-lia-message-uid");
if (mszId != null) {
mszListl.push(mszId);
}
});
var mszListid = mszListl;
console.log("mszListl:",mszListl);
},2000)
}else{
var mszListid = mszList_l;
}*/
console.log("mszList_l:",mszList_l.length);
angular.forEach(mszList_l, function (value) {
if (document.querySelectorAll('div.lia-js-data-messageUid-' + value).length > 0) {
var rootElements = document.querySelectorAll('div.lia-js-data-messageUid-' + value);
}else if(document.querySelectorAll('.lia-occasion-message-view .lia-component-occasion-message-view').length >0){
var rootElements = document.querySelectorAll('.lia-occasion-message-view .lia-component-occasion-message-view')[0].querySelectorAll('.lia-occasion-description')[0];
}else {
var rootElements = document.querySelectorAll('div.message-uid-' + value);
}
angular.forEach(rootElements, function (rootElement) {
if (value == '590217' && "ForumTopicPage" == "TkbArticlePage") {
rootElement = document.querySelector('.lia-thread-topic');
}
/* V1.1 Remove from UI */
if (document.getElementById("tr-msz-" + value)) {
document.getElementById("tr-msz-" + value).remove();
}
if (document.getElementById("tr-sync-" + value)) {
document.getElementById("tr-sync-" + value).remove();
}
/* XPath expression for subject and Body */
var lingoRBExp = "//lingo-body[@id = "+"'lingo-body-"+value+"'"+"]";
lingoRSExp = "//lingo-sub[@id = "+"'lingo-sub-"+value+"'"+"]";
/* Get translated subject of the message */
lingoRSXML = doc.evaluate(lingoRSExp, doc, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
for(var i=0;i 0){
angular.forEach(document.querySelectorAll(".PageTitle"), function(subEle) {
subEle.textContent = sub_L;
});
}
}
}
// Label translation
try{
var labelEle = document.querySelector("#labelsForMessage");
if(!labelEle){
labelEle = document.querySelector(".LabelsList");
}
if(labelEle) {
var listContains = labelEle.querySelector('.label');
if (listContains) {
/* Commenting this code as bussiness want to point search with source language label */
// var tagHLink = labelEle.querySelectorAll(".label")[0].querySelector(".label-link").href.split("label-name")[0];
var lingoLabelExp = "//lingo-label/text()";
trLabels = [];
trLabelsHtml = "";
/* Get translated labels of the message */
lingoLXML = doc.evaluate(lingoLabelExp, doc, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
var labelsLength = document.querySelector(".LabelsList").querySelectorAll(".label").length;
var labelSnapshotLength = lingoLXML.snapshotLength;
if (labelsLength == labelSnapshotLength){
for (var k = 0; k < lingoLXML.snapshotLength; k++) {
//trLabels.push(lingoLXML.snapshotItem(i).textContent);
if (k != 0) {
//trLabelsHtml = trLabelsHtml + '