Hi,
Please give more details. Like which pin you want to use for this and nature of frequency(like sine, square)??
Amit
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.
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 }
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.
[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';
}
How about LPc2148 chip? is it compact able with USB??
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?