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.

measuring every 2 seconds

Status
Not open for further replies.

shaneelal

Member level 1
Joined
Nov 16, 2004
Messages
38
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
553
555 timer rtc

I"m working on a project that measure and displays wire speed,voltage and current of a welding station.
One device measures wire speed,displays it onto an LCD and transmits the wire speed to another device using USART.
Another device senses voltage and current. The second device has to display all three readings onto an LCD and also to a video display using a video module.
I'm supposed to measure the current and voltage every 2 seconds. Both devices utilize 18f452.
Wire speed meter transmits to main device,main device transmits to video module.
Do I need a real time clock for both devices to coordinate transmission of data using rs 232 and also measuring voltage and current every two seconds?
Could you tell me more on how to use a real time clock? Which one should I use? Is there any sample code,I'm using MPLAB-C18 compiler.
 

18f4520 uart asm

Hi,

No need for real time clock. 2 seconds is a LONG time. What you need to do is:
1. Use an interupt or any other way to generate a flag every 2 seconds.
2. Send the data to the main PC around the 2 seconds.
3. In the main PC wait to receive all data and then display it.

Another way(Master/Slave ):
1. Have the PC ( Master ) send a request to the remote ( Slave ) Every 2 seconds.
2. After the master fateched all data, the master will display it on the LCD.
This method you will get a constant drift, but it will be only from the master. You can use an expensive resonator so it will be more accurate over tempreture.
Good luck.
 

    shaneelal

    Points: 2
    Helpful Answer Positive Rating
opentimer0 1sec

Hi,
hmm u can actually write an interrupt service routine that is short to interrupt.
Can make use of Timer0 or Timer1 to interrupt each time whenever there is an overflow of the 16 bit timer. If u are using a 20 Mhz crstal, and with a 16 bit timer, each overflow will take ard 13.1 ms.. then u can use a counter that count to 76, which will then give u 1 second. :)
 

The PIC has one USART. Using two PIC 18f452. One device transmits to the other the wire speed,the other senses current and voltage ,displays it onto a lcd and sends all data (wirespeed,voltage and current to a video module).
The first PIC only transmits,it doesn't recieve anything. The second device transmits to the video module. Each device can be turned on at differnent times,with the real time clock I could have both of them in sync. How will I know when the transmit the wire speed to the other device,can I store it till the second device is ready to display?
 

Use the first PIC (wire speed) as the master 2 sec clock. By sending "wire speed" evere 2 secs to the second PIC it will cause the second PIC to read voltage/current and then feed this information together with the wire speed to the On-Screen Display video module ..
If you want to you can use a DS1307 or DS1337 to interrupt the first PIC every second or so.. https://www.google.com/search?hl=en&lr=&q=ds1307
 

    shaneelal

    Points: 2
    Helpful Answer Positive Rating
hi,

its very simple 2 get 1 sec interrupt if ur uCs timer1 Osc pins r free.
u can connect 32.768khz crystal to these pins, use timer1 clk sorce as external osc. and load timer1 with 0x8000. u ll get overflow in 1sec.....in ISR reload the timer and run....in this way u can generate 1 sec interrupt.....
using 1 sec interrupt ,2 seconds is no problem.......after 2 seconds r over initiate ur activity reqd. to be done.

ive used this with same controller as urs.i.e.pic18f452.

for more info and sample code...goto
www.microchip.com AND search datasheet of 18f4520 not 18f452. a8f4520 is advanced version, but its timer 1 is similar to timer 1 of 18f452. so in that section u will get help on code also and hardware also.....
u can directly use that with pic 18f452.....this way u can elliminate RTC and communication protocol reqd for RTC to b implemented.

Best regards.
suryakant.
 

    shaneelal

    Points: 2
    Helpful Answer Positive Rating
I already posted you some sample code in your other thread about 2 second delays
 

I'm very grateful for all the help I've gotten.
I've tried to use a rtc,realized wasn't as easy as I thought.I'll try and say what I'm trying to achive and give some sugestions which I'll like comments on.
I"m building two devices.
1. measures wire speed and displays it on an LCD screen
2. (main device)measures current and voltage every 2 seconds. Takes current,voltage and wirespeed displays it on an LCD and also transmits via rs232 serial communication to a video module to display onto a video screen.

The wire speed meter uses timer0 and timer1 to determine wire speed.
Options:-
a).My original plan was to use an external interrupt every 2 secs on the wire speed meter to transmit to the main device using the PIC's UART ie rs232. And when the main device recieves the wirespeed it would trigger an interrupt on reciept and then measure current and voltage, display onto LCD and transmit all data to video module.I was planning to use a rtc to generate the interrupts every 2 seconds. Then I thought of using a 555 timer to generate the interrupts every 2 seconds, will that be workable?

b).Have the 555 timer on the main device,generating interrupts every 2 secs. The wirespeed will transmit as soon as it has calculated a wirespeed. Can the PIC buffer recieved UART bytes? When the 2 secs occur and interrupt happens,the PIC would read the last transmitted wirespeed,obtain the current and voltage by ADC and display it on an LCD and also transmit all data to video module.
The PIC will stay in the ISR for a relatively long time.

I'm in favour of option b. I'm not sure how the 18f452 will handle continuously recieved data and not reading it,when I'm ready to read the wirespeed the last recieved data would be ready for me?
The main device also has a 18f452,I was thinking to use timer1 to wait for the 2 seconds to pass.When I'm doing other things,will timer1 still be still be timming the 2 seconds?

How can I configure the 555 timer to give me interrupts every 2 seconds?
Any other options are gladly welcomed.
 

I've tried to use a rtc,realized wasn't as easy as I thought
Please dont take offence, but using an I2C is quite basic, and I think if you cant master that then you may be in trouble with the other parts of your project, I can supply some code for read/write to I2C if you like but they are in assembly and written for 16F series.

Then I thought of using a 555 timer to generate the interrupts every 2 seconds, will that be workable?
It would, although it seems a waste of the pics resources, not to mention an additional component.

Have the 555 timer on the main device,generating interrupts every 2 secs. The wirespeed will transmit as soon as it has calculated a wirespeed. Can the PIC buffer recieved UART bytes
Yes, some PICS have onboard UART, others dont, but you can still do it in software without, my method is to use an 232 MAX IC and use software on the PIC, simply because I have heard rumours of problems with the PICs UART in some case. The software involved is very easy, as is the circuitry.

I'm not sure how the 18f452 will handle continuously recieved data and not reading it,when I'm ready to read the wirespeed the last recieved data would be ready for me
The PIC will only "respond" to anything you tell it to, its up to you and your program what you do with anything on the I/O ports

The PIC will stay in the ISR for a relatively long time
Thats fine as long as you are aware that whilst in an ISR then the main program will be "paused"

I was thinking to use timer1 to wait for the 2 seconds to pass.When I'm doing other things,will timer1 still be still be timming the 2 seconds

The timer will run and run, however its up to your program to do something with it, its usual to increase "variables" as the timer "ticks" until you have reached a predetermined value in these variables, this is done in an interrupt .

did you look at http://www.winpicprog.co.uk/pic_tutorial.htm ? just about everything we covered just now is on there, but thats for a 16F not a 18F, I havnt yet upgraded to the 18F, I started on the 16F because it was considered somewhat easier for a beginner.
 

    shaneelal

    Points: 2
    Helpful Answer Positive Rating
Thank you eggplant. I'm writing just to be sure of one thing. If I transmit to the UART rx pin of another PIC,say the other PIC doesn't read it in. I transmit again still doesn't read in,transmit again and still don't read in,but before the 4th reception I need the last recieved value,will I be able to read it?
What I'm trying to say is that I want to be able to read from the rx pin of the PIC the last transmitted byte.
If that can't work,I'll interrupt every 2 seconds on the first device to transmit and have an interrupt occur on the second device on reception to perform voltage and current readings.
Please forgive me if I may ask ridiculous questions,I just need to be sure.
 

OK,I just realised that the timers can operate independently of the operations of the rest of the PIC. I need the pic to do a certain task every 2 seconds,it has to be every 2 seconds.Can I used timer0 on the PIC18f452 to do this.I'm really pressed for time,could someone help me do this.I"m using c18 compiler.Right now I have code written waiting for an interrupt to occur every 2 seconds via a 555 timer.
Every 2 seconds I need to read the USART for data transmitted by another PIC,perform ADC on 2 channels display results onto LCD and tv screen.
Should I count for 2 seconds on the timer,or allow it to interrupt on overflow and count number of overflows till I get required 2 seconds. I"m using a 4MHz clock.
 

Do I have to clear the TMR0IE in the ISR? Do I have to do anything to renable the timer to interrupt? Do I have to reset the timer or after it overflows it resets itself automatically? Is there anything that looks wrong in my code?
I'm using a 4MHz clock. Internal clock source,therefore using 1MHz.
With a pre scaler or 1:32 gives 31250Hz.
Period being 0.000032 secs.
16 bit wide 0.000032*2^16 = 2.097 =2.1 seconds
timer0 should overflow every 2.1seconds.
I believe the timer will continue timming after the interrupt has occured,while in the ISR. Please tell me I'm right.

This is a sample of the code I've written
Code:
rom char sp_units[10]  = "mm/sec"; //The rom qualifier denotes that the object is
									//located in program memory
rom char vol_units[10] = "Volts"; 
rom	char cur_units[10] = "Amps";
rom	char welcome[20] = "Welding Monitor";
rom	char cursorL1[5] = "{A17" ;
rom	char cursorL2[7] = "{C0202"	;
rom	char cursorL5[7] = "{C0204";
rom	char cursorL7[7] = "{C0206";
rom	char cursorL9[9] = "{C0209";
rom	int convFactor = (5.0 / 1024);

void main(  )
{	
//config RBO for interrupts
//OpenRB0INT(  PORTB_CHANGE_INT_ON & PORTB_CHANGE_INT_ON & RISING_EDGE_INT & PORTB_PULLUPS_ON );                                                                                                                
// configure external LCD
OpenXLCD( FOUR_BIT & LINES_5X7 );//four bit mode,multiple line display 

OpenTimer0( TIMER_INT_ON & //interrupt on
			T0_16BIT &      //16bit mode
            T0_SOURCE_INT & //internal clock source
            T0_PS_1_32 );  //1:32 prescale


OpenUSART( USART_TX_INT_OFF & USART_RX_INT_OFF &
           USART_ASYNCH_MODE & USART_EIGHT_BIT &
		   USART_BRGH_HIGH &
           USART_CONT_RX,25);

OpenADC(ADC_FOSC_8 & ADC_RIGHT_JUST &
		ADC_8ANA_0REF,ADC_CH0 & 
		ADC_INT_OFF);



INTCONbits.GIE = 1;
while (1)
	{
	
	}

}


#pragma interrupt system //save=PRODH, PRODL,section( ".tmpdata" )
void system(void)
{
	
	int current_adc;
	int voltage_adc;
    int voltage;
	int current;
	char speed[7];
	char voltage_str[7];
	char current_str[7];

////	char sp_units[10]  = "mm/sec";
//    char vol_units[10] = "Volts"; 
//	char cur_units[10] = "Amps";
//	char welcome[20] = "Welding Monitor";
//	char cursorL1[5] = "{A17" ;
//	char cursorL2[7] = "{C0202"	;
//	char cursorL5[7] = "{C0204";
//	char cursorL7[7] = "{C0206";
//	char cursorL9[9] = "{C0209";


	INTCONbits.TMR0IE = 0; 
	SetChanADC(ADC_CH0); //select voltage channel
	Delay10TCYx(3);
	ConvertADC();
	while( BusyADC());
	voltage_adc=ReadADC();
	voltage = (voltage_adc * convFactor  *100);
	SetChanADC( ADC_CH1 );//select current channel
	Delay10TCYx(3);
	ConvertADC();
	while( BusyADC());
	current_adc=ReadADC();
	current = (current_adc *1.2* convFactor  *600);
	while(!DataRdyUSART());
	getsUSART(speed , 7);//obtain speed
	while (BusyUSART()); //TEST TO SEE IF CAN REMOVE
/***************write to LCD*******************/
	while(BusyXLCD());
	SetDDRamAddr(0x00);
	putrsXLCD( clear );
	while(BusyXLCD());
	SetDDRamAddr(0x40);
	putrsXLCD( clear );
	while(BusyXLCD());
	SetDDRamAddr(0x10);
	putrsXLCD( clear );
	while(BusyXLCD());
	SetDDRamAddr(0x1C);
	while(BusyXLCD());
	putrsXLCD( sp_units );
	while(BusyXLCD());
	SetDDRamAddr(0x14);
	while(BusyXLCD());
	putsXLCD(speed);
	while(BusyXLCD());
	SetDDRamAddr(0x48);
	while(BusyXLCD());
	putrsXLCD( cur_units );
	while(BusyXLCD());
	SetDDRamAddr(0x40);
	itoa(current,current_str);
	while(BusyXLCD());
	putsXLCD(current_str);
	while(BusyXLCD());
	SetDDRamAddr(0x08);
	while(BusyXLCD());
	putrsXLCD( vol_units );
	while(BusyXLCD());
	SetDDRamAddr(0x00);
    itoa(voltage,voltage_str);
	while(BusyXLCD());
	putsXLCD(voltage_str);
/************write to tv screen*************************/
	while (BusyUSART());
	putrsUSART(cursorL1 ); //clear screen
	while (BusyUSART());
	putrsUSART( cursorL2 );
	while (BusyUSART());
	putrsUSART( welcome );
	while (BusyUSART());
	putrsUSART( cursorL5 );
	while (BusyUSART());
	putsUSART( speed );
	while (BusyUSART());
	putrsUSART( sp_units );
	putrsUSART( cursorL7 );
	while (BusyUSART());
	putsUSART( current_str );
	while (BusyUSART());
	putrsUSART( cur_units );
	while (BusyUSART());
	putrsUSART( cursorL9 );
	while (BusyUSART());
	putsUSART( voltage_str );
	while (BusyUSART());
	putrsUSART( vol_units );
}
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top