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.

Need help with PIC 18F4550 timer with multiplexing

Status
Not open for further replies.

D.john

Newbie level 3
Joined
Dec 27, 2010
Messages
3
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,327
I am trying to use PIC18F4550 IC chip to do AD conversion (based on the temperature in the room) and then using the result to determine the speed (requiring delays, 3 different lvl) of a motor. However, I would also like to have 2 LED 7 seg-display to show the temperature of the room. But this requires me to use timer and multiplexing (using timer too). This causes the program to have too much delay and the 2 7-seg display seems to blink, 1 after another.


Can anyone kindly give me a guide on how to use timer properly together with the motor delay? Thanks.

Regards,
John.
 

1.try to use 2 microcontroller, some like pic16F or even pic12F to control the 7 segment or do the temp convert, then your computation time will be better.
2. use RTOS, micrium and freeRTOS is available and it will help you to do task simultaneously, thus, during delay, the RTOS will switch task to the one which is ready, but to use an RTOS, it might be quite hard but a good sftware solutio :)
 

Sorry but I am still a newbie to microcontroller, what is an RTOS? So far what I have learnt is some basics of PIC18F4550 microcontroller chip and some usage of it.

Would you mind explain abit more about RTOS or if possible narrow down to solely using PIC18F4550 chip and MPLAB IDE v8.36. Sorry for the inconvenince caused and I would like to thank you for taking your time to help me:)
 

RTOS is some software that enable each task to be excecuted when it is ready. In a simple system where you have 3 led blinking at different rate say 1ms, 2ms and 3ms. So, every 1ms led 1 will blik, 2ms led 2 will blink and 3ms led 3 will blink. so durig the delay fuction, normal PIC execution will wait till the delay of led 1 to finished then blink led 2. RTOS, will execute those that is ready. means if its time for led 3 to blink it will blink, then if the tur comes for led 1, the led 1 will blink
 

Hi,
A much easier solution than RTOS would be to use interrupts, and have different timings using the timer interrupt. Please go through the interrupt chapter in the datasheet and when you are clear about the timer interrupt, it will seem much easier. Study interrupts carefully as it is the most important thing for multitasking using a microcontroller.
By the way, RTOS is Real Time Operating System - read here: Real-time operating system - Wikipedia, the free encyclopedia

Hope this helps.
Tahmid.
 
Hi, thanks for the help for both of you.

Here are my enquiries:

For RTOS does it need an application to use it or is it part of some useful abilities the chip can make use of? Btw, the website contains many information which is very good. But a pity, I am poor in my understanding, could you mind say it in a simpler way please>.< Thanks.


As for timer interupt, I tried it out. This is roughly how my program looks like:


#include <p18F4550.h>
#include <delays.h>
#define HIGH 0x45 //HIGH water level indicator
#define MID 0x22

unsigned char j;

void ISR_Timer0_Int();

//*************
#pragma udata

extern void _startup (void); // See c018i.c in your C18 compiler dir

#pragma code _RESET_INTERRUPT_VECTOR = 0x000800
void _reset (void)
{
_asm goto _startup _endasm
}
//**************


#pragma code

#pragma code _HIGH_INTERRUPT_VECTOR = 0x000808 // Location of high priority interrupt
void _high_ISR (void)
{
_asm
goto ISR_Timer0_Int // Look for the ISR for INT0
_endasm
}

#pragma code _LOW_INTERRUPT_VECTOR = 0x000818
void _low_ISR (void)
{
;
}
#pragma code
#pragma interrupt ISR_Timer0_Int

void ISR_Timer0_Int() // Timer0 Interrupt Service Routine (ISR)
{
if (INTCONbits.TMR0IF) // TMR0IF:- Timer0 Overflow Interrupt Flag Bit
// 1 = TMR0 reg has overflowed
// 0 = TMR0 reg has not overflowed
{
TMR0H = 0xCD; // Timer0 start value = 0x48E5 for 1 second
TMR0L = 0xFF;

PORTB = 0b00000100; //enable DIG2
PORTD = 0b01011011; //display 2
Delay100TCYx(255); //LEDs on for a while, this is where i keep changing the delay time but it doesnt work. either too long and the results blink or //too short, motor doesnt spin.

PORTB = 0b00000010; //enable DIG1
PORTD = 0b00000110; //display 1

INTCONbits.TMR0IF = 0; // Reset TMR0IF to "0" since the end of
// the interrupt function has been reached
}
}

/declaring part

RCONbits.IPEN =1; // Bit7 Interrupt Priority Enable Bit
// 1 Enable priority levels on interrupts
// 0 Disable priority levels on interrupts

INTCONbits.GIEH =1; // Bit7 Global Interrupt Enable bit
// When IPEN = 1
// 1 Enable all high priority interrupts
// 0 Disable all high priority interrupts

T0CON = 0b00000111; // bit7:0 Stop Timer0
// bit6:0 Timer0 as 16 bit timer
// bit5:0 Clock source is internal
// bit4:0 Increment on lo to hi transition on TOCKI pin
// bit3:0 Prescaler output is assigned to Timer0
// bit2-bit0:111 1:256 prescaler


INTCON2 = 0b10000100; // bit7 :pORTB Pull-Up Enable bit
// 1 All PORTB pull-ups are disabled
// bit2 :TMR0 Overflow Int Priority Bit
// 1 High Priority

T0CONbits.TMR0ON = 1; // Turn on timer
INTCONbits.TMR0IE = 1; // bit5 TMR0 Overflow Int Enable bit
// 0 Disable the TMR0 overflow int

INTCONbits.TMR0IF = 0; // bit2 TMR0 Overflow Int Flag bit
// 0 TMR0 register did not overflow



//the conversion part

if(ADRESH > HIGH)
{
PORTCbits.RC2 = 1; // Turn on Motor
}
else if (ADRESH > MID && ADRESH < HIGH)
{
PORTCbits.RC2 = 1; // Turn on Motor
Delay10KTCYx(80);
PORTCbits.RC2 = 0; // Turn on Motor
Delay10KTCYx(80);
}
else
{
PORTCbits.RC2 = 1; // Turn on Motor
Delay10KTCYx(10);
PORTCbits.RC2 = 0; // Turn on Motor
Delay10KTCYx(10);
}

hope your can check whether am i right a not. Thanks again guys:)
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top