Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[ARM] Generating the variable frequencies from 1hz to 12hz using LPC1115 micro controller

Status
Not open for further replies.

robo111

Junior Member level 2
Joined
Mar 28, 2016
Messages
24
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
208
Hi Friends,

I'm using LPC1115 Micro controller (ARM7) and KEIL compiler.

Now I need to generate the variable frequency 1hz to 12hz with step of 1hz increment

by using the match registers.

I'm newer to this micro controller.

so anybody can guide me to achieve this task.

Thanks in advance
robo
 

Hi,

Please give more details. Like which pin you want to use for this and nature of frequency(like sine, square)??

Amit
 

Hi,

Please give more details. Like which pin you want to use for this and nature of frequency(like sine, square)??

Amit

Thanks for the reply,

I'm using the 16bit C\T register..and checking the o/p at pin no 17 i.e. PIO1_9 of MAT0 reg.

currently I'm getting square wave of constant frequency(2hz).. I need to vary the freq from

2hz to 12hz with step of 1 hz. for getting 2hz I'm varying the MAT3 and PR(pre scaler reg)

kindly advice
 

In the pin no 17 PIO1_9 of MAT0 reg,
I should generate the variables freq. on the same pin
 

1 * 2 * 3 * 4 * 5 * 6 * 7 * 8 * 9 * 10 * 11 * 12 = 479 001 600 Hz
4 = 2 * 2
6 = 2 * 3
8 = 4 * 2
9 = 3 * 3
10 = 5 * 2
So, 1-4-6-8-9-10 can be excluded
2 * 3 * 5 * 7 * 11 * 12 = 27720 Hz
So, timebase for timer should be 27720 Hz
That means, that you need oscillator on 15.994 MHz for example. Or try find something closer. Hope you understand this calculations.
 

1 * 2 * 3 * 4 * 5 * 6 * 7 * 8 * 9 * 10 * 11 * 12 = 479 001 600 Hz
4 = 2 * 2
6 = 2 * 3
8 = 4 * 2
9 = 3 * 3
10 = 5 * 2
So, 1-4-6-8-9-10 can be excluded
2 * 3 * 5 * 7 * 11 * 12 = 27720 Hz
So, timebase for timer should be 27720 Hz
That means, that you need oscillator on 15.994 MHz for example. Or try find something closer. Hope you understand this calculations.


Hi,

I understood part of it,so could you explain in more details??


Below is the code where I'm getting the desired frequency by varying PR and MR3
registers...
Like by going through the user manual got to know that FCLKOUT is 48 MHz,
so to get the output of 3Hz need to assign values to prescaler & match register
respectively i.e., 48 Mhz/4000*4000 = 3Hz.

So now my problem is how to generate the frequency continuously from 1hz to 12hz,
with step variation of 1 [i.e., 3hz,4hz,5hz,6hz etc..]
Should I use timer for this operation or interrupts.
Please do suggest me.


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <LPC11xx.h>            /* LPC11xx Peripheral Registers */
#include "system_LPC11xx.h"
 
int main()
{
SystemInit();
LPC_SYSCON->SYSAHBCLKCTRL |= (1<<16) |(1<<6) | (1<<8) ;
LPC_IOCON ->PIO1_9 |= (1 << 0);             //PIN1_9 = CT16B1_MAT0
LPC_TMR16B1 ->MR0 = 1000;                   //50% Duty Cycle
LPC_TMR16B1 ->PR = 2000;//for 12hz freq
LPC_TMR16B1 ->MR3 = 2000;//for 12hz freq    //Cycle Length
LPC_TMR16B1 ->MCR |= (1 << 10);             //TC Reset on MR3 Match
LPC_TMR16B1 ->PWMC |= (1 << 0);             //PWM Mode
LPC_TMR16B1 ->TCR |= (1 << 0);              //GO
}

 
Last edited by a moderator:

You can use PWM with 50% duty cycle. Interrupt will not needed.
But to get all intermediate frequencies, your time base should be devidable by all frequencies in list. That's why I choosed 27720, it can be devided by all digits from 1 to 12.
27720 / 11 = 2520
27720 / 7 = 3960
27720 / 5 = 5544
All digits after equal sign is you prescaller values.
 

You can use PWM with 50% duty cycle. Interrupt will not needed.
But to get all intermediate frequencies, your time base should be devidable by all frequencies in list. That's why I choosed 27720, it can be devided by all digits from 1 to 12.
27720 / 11 = 2520
27720 / 7 = 3960
27720 / 5 = 5544
All digits after equal sign is you prescaller values.

Thank you!!

yes I've divided the choosed value 27720.

27720 / 11 = 2520
27720 / 7 = 3960
27720 / 5 = 5544
5544/3=1848
1848/1=1848

and assign the values to PR reg and remaining lines kept as it is!!
LPC_TMR16B1->PR= 2520 |3960 |5544 |1848; and
the checked the o/p at pin no 17 in the Oscilloscope but freq is 847mHZ comes..
NO changes in freq.. so how to do it?
 

Hi,

Easirider's solution is the perfect solution.
This is the "least common multiple" solution.

With your low frequencies you could use about any counter frequency that is near, but above 65536Hz.

The error caused by the integer dividers should be low... below 0.1%.

Klaus
 

Thanks to everyone,

I understood the concept of dividing the frequencies by Easirider's solution but how to assign those

values to the pre scaler regs and I'm not getting the exact freq.. please suggest in the

programming part to assign the values ..


Thanks a lot
 

Hello Friends,

In the LPc1114 micro controller, now I've designed the time function using timer_32_ interrupts and time selection

has been made by user option. now i need to generate the frequecny w.r.t. to time

i.e if 9.6 freq should generate in 1 min the in then next min it should varies

i.e. frequency should varies by one step by increment of every one minutes.

how to do it???

Kindly suggest on this.


Thanks in advance

- - - Updated - - -

Hi,

In the LPc1115 controller, how can I vary the frequency by pre scaler register or match registers??

i.e. which parameter should keep constant because I need generate the freq with step increment of 0.5 hz
 

Hi,

Don't expext that we know all microcontrllers an their hardware options.
Although the function of frequency generation may be similar we don't know the setup options of your microcontroller.
(Is it now 1114 or 1115?)
So please tell us the setup options and we can tell you what to do.

*****
What does that mean? "i.e if 9.6 freq should generate in 1 min the in then ..."
What is 9.6?
I didn't get your whole description.
***

Now you talk about 0.5Hz increments, but before you talk about 1Hz increments.
Did the specification change now?

To keep it simple, I'd try to initialize the prescaler and don't change it. Change the frequency only with the match register values.

What accuracy of the particular frequency do you expect? Value.

Klaus
 

Hello,

I'm using LPC1115(ARM7) micro controller and KEIL U vision4 IDE.

Task description: now I have generate the freq of 9.6 hz by varying the PR and match regs using the timer_16_1
interrupts. and time function by using timer_32_0 interrupts.
now if I selected the time as 5 min then start freq will be 9.6 hz when the timer decrements to every one step
then(4min,3min...00) freq. should be vary by 1hz i.e.
5min=9.6hz
4min=9.7hz
... so on.. until timer reaches to 00:00 below is my code part and check it.and I'm checking the freq o/p across oscilloscope.

As per the below code calculation for the frequency for 3hz i'm getting is:
OUTPUT FREQ= CRYSTAL FREQ / (MR3*PR);
So for 3hz 48Mhz / (4000*4000) = 3Hz.

By keeping PR value constant how to rewrite the above equation in match registers.

Kindly go through the below code:
Code:
[code]#include
#include "LPC11xx.H" 
#include "glcd_api.h"

#define	INCR	(char)1
#define	HOLD	(char)0
#define	DECR	(char)-1

char line_buf[21];
volatile int seconds_indicator;
unsigned char DONE_str[] = "DONE";
//static char seconds_str[] = "* *";
unsigned char TIME_str[] = "TIME_SEL";

unsigned int temp_hours_selected=0;
unsigned int temp_minutes_selected=02;
unsigned int hours_selected=0;
unsigned int minutes_selected=02;

volatile signed char hours_remaining;
volatile signed char minutes_remaining;
volatile signed char seconds_remaining = 59;	
signed int timer_flag;

unsigned int wait_for_any_key_counter_0;
unsigned int wait_for_any_key_counter_1;
unsigned char restart_therapy;

unsigned long spill_over_count;	

unsigned int timer1_overflow_count = 0;
unsigned int timer0_overflow_count = 0;
unsigned char spill_over_count_loaded;
unsigned char spill_over_count1_loaded;
unsigned char show_time_flag;
unsigned char show_seconds_flag;
unsigned char therapy_is_over;

unsigned int b,j;
int current_frequencyx10;
unsigned long cycle_time_microsec;

struct THERAPY
{
unsigned int match3;
unsigned int match0;
signed char inc_hold_dec;
unsigned int prescal;	
};

signed int inc_hold_dec;

char ma3[10];
char ma0[10];
char pr[10];
char a[20];

struct THERAPY recover[]=
{
4000,4000,2000, //3hz

2000,1000,2500, //9.6hz//mr3,mr0,pr

1390,695 ,2500, //14.1hz	
};

int phase_num;
unsigned int mat3;
unsigned int mat0;
unsigned int pre;
void delay(void);
void tostring(char [],int);

void TIMER32_0_IRQHandler(void) //ISR ROUTINE//interrupt3
{
if(therapy_is_over == 0)
{
if(spill_over_count1_loaded == 1)
{
spill_over_count1_loaded = 0;
timer1_overflow_count = 0;
if(LPC_TMR32B0->IR & 0x01)
{
LPC_TMR32B0->IR=1; //clear interrupt flag //

if((seconds_remaining == 0) && (minutes_remaining == 0) && (hours_remaining == 0))
{
hours_remaining = 0;
minutes_remaining = 0;
seconds_remaining=0;
therapy_is_over = 1;
init_xy_axis(PAGE0 + 4 , COL0 + 34); 
lcd_display_string((unsigned char*)line_buf);
sprintf(line_buf, "%s", DONE_str); 
} 

else if(seconds_remaining ==-1)
{
seconds_remaining = 59;
minutes_remaining--;
}
else if(minutes_remaining ==-1)
{
minutes_remaining = 59;
--hours_remaining;
}
else
{
seconds_remaining--;
}
show_time_flag = 1;
}
}

else
{
if((timer1_overflow_count % 10) == 0)
show_seconds_flag = 1;
timer1_overflow_count++;
if(timer1_overflow_count == 120) //1230,120
{
spill_over_count1_loaded = 1;
LPC_TMR32B0->TC=0x00; //here assigned values for * blinking //0x82 is correct//0x84 //0x88=6sec
LPC_TMR32B0->PR=0x01; //here assigned values for * blinking 
}
}
} 

}


void Timer32_0_init(void) //Timer32 bit initialization and PWM genaration //for timer operation
{
LPC_SYSCON->SYSAHBCLKCTRL |= (1<<16) | (1<<6) | (1<<9); //cloc+3
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 */

LPC_TMR32B0->MR0 = 50 * ((SystemCoreClock/(LPC_TMR32B0->PR+1))/100); //[if we won't use MR0 timer operation stops] /* Generate interrupt each 10 ms */

LPC_TMR32B0->MCR = 0x03;
LPC_TMR32B0->TC=0x00; //0x00;//0x82 is correct//0x84 //0x88=6sec
LPC_TMR32B0->PR=0x01; //1
NVIC_EnableIRQ(TIMER_32_0_IRQn);
/* initialize timer */
LPC_TMR32B0->TCR=0; //0 or 1 is not affected in timer operation or in freq

}

void timer162(void)
{	
LPC_SYSCON->SYSAHBCLKCTRL |= (1<<16) | (1<<6) | (1<<8);
LPC_IOCON->PIO1_9 |= (1 << 0); // Pin no 17 = CT16B1_MAT0(checking out put )
LPC_TMR16B1->PWMC |= (1 << 0); // PWM Mode channel zero fro CT16B1.
LPC_TMR16B1->MCR |= (1<<10) ;// TC reset on MR3 Match
LPC_TMR16B1->MR3 = mat3; //4000//22900;; // Cycle Length	
LPC_TMR16B1->MR0 = mat0; //11200; // 50% Duty Cycle
LPC_TMR16B1->PR = pre;
LPC_TMR16B1->TCR = (1<<0); //TC & PC enabled for counting.

}

//Below is the code for frequency generation///
void StruVariable(void)
{
mat3=recover[phase_num].match3;
mat0=recover[phase_num].match0;
pre=recover[phase_num].prescal;

init_xy_axis(PAGE0 + 6,COL0 + 34 ); 
sprintf(line_buf," %02d:%02d ", hours_remaining, minutes_remaining);
lcd_display_string(line_buf);

tostring(ma3,mat3);
init_xy_axis(PAGE0,COL0);
lcd_display_string((unsigned char*)ma3);//

tostring(ma0,mat0);
init_xy_axis(PAGE0+2 ,COL0);
lcd_display_string((unsigned char*)ma0);//

tostring(pr,pre);
init_xy_axis(PAGE0+4,COL0);
lcd_display_string((unsigned char*)pr);//

cycle_time_microsec = 10000000/current_frequencyx10;

timer162();
phase_num++;

if(phase_num>=6)
{
phase_num=0;
}
else if(phase_num==0)
{

LPC_TMR32B0->TCR = 0;
}

}

void delay(void)
{
unsigned long i;

for(i=0;i<1000000;i++);//10000000
mat3=recover[phase_num].match3;
mat0=recover[phase_num].match0;
pre=recover[phase_num].prescal;

}

int ma;
int ba;

int main(void) 
{
init_glcd();
glcd_clear();
back_light_on();

timer_flag=0; //set the flag for timer operation
therapy_is_over = 0;

Timer32_0_init();

show_time_flag = 0;
show_seconds_flag = 0;
seconds_indicator = 0;

while(1)
{
if(show_seconds_flag == 1)
{
show_seconds_flag = 0;
Timer32_0_init();
}

while(1)
{
hours_selected = temp_hours_selected;
minutes_selected = temp_minutes_selected;
hours_remaining = hours_selected;
minutes_remaining = minutes_selected;

LPC_TMR32B0->TCR = 1;

while(1) 
{
StruVariable();
delay();

}
}

}
}

void tostring(char str[], int num)
{
        int i, rem, len = 0, n;

        n = num;
        while (n != 0)
        {
            len++;
            n /= 10;        }
        for (i = 0; i < len; i++)
        {
            rem = num % 10;
            num = num / 10;
            str[len - (i + 1)] = rem + '0';
        }
        str[len] = '\0';
}



Thanks in advance
 

Hi Friends,

Presently I'm working on LPC1115FBD48 micro controller.
any one please tell that can we interface the USB with micro controller?
is this controller will support for the USB interfacing because I've searched the LPC1115 user manual but
their are not mentioned about this USB..so is there any standard drivers for USB to interface with this LPC11115????




Thanks
 

Thanks for Reply,

Is there any external hardware(circuit) will support for the interface with USB???

or any drivers support??
 

Hi,

Look for:
* USB to serial interface IC
* USB to parallel interface IC

Klaus
 

Ok thank you,

How about LPc2148 chip? is it compact able with USB??
 

LPc2148 support usb. But make it works will require advanced knowledges. You better use FT232 or similar bridge
 

Hi,

I never used those LPC devices...

How about LPc2148 chip? is it compact able with USB??

It took me only a few seconds to find the answer!

On the first page of the datasheet:
* You see the USB logo.
* In the headline it says "USB 2.0 full-speed device"
* and at least 3 other occurances (on the first page) that it includes the USP periferal.

What else do you need?

Please do such simple research on your own before posting!

Klaus
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top