The Philippine Electronics and Technology Forum
May 17, 2012, 06:22:55 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
 
   Home   Help Search Login Register  
Pages: [1] 2 3   Go Down
  Print  
Author Topic: PowerOnDelay na OverKill!!! [Zilog]  (Read 3630 times)
marcelino
Moderator
Solar Power Satellite
*****

Pogi/Ganda Points: 256
Offline Offline

Posts: 5958


...keep moving forward! - Robinson's


« on: August 25, 2009, 11:21:46 PM »

Totoo OVER KILL talga to...
At mas mahal ha!!! heheh Grin

Most part of the code is based on sir paranz tutorial.


Code:
/*
   Power On Delay For Air Condition with Override Switch Using Z8F0823  

* Timer0 -  For Direct LED drive display during waiting time
* Timer1 -  CountDown tick for the given TurnOnTime (in seconds)

Processor : Z8F0823
Oscillator: Internal Oscillator : 5.53 MHz (to be exact = 5.52960MHz)
 

*Based on the tutorials of Sir Paranz of Elab


marcelino  (August 25, 2009)
Note: this is my first complete working code using Zilog CPUs. ;D ;D ;D
*/


#include<ez8.h>

#define OverflowValueTMR0 5400 // 125ms for 5.52960MHz
// (1/5.53M) x 5400 x 128

#define OverflowValueTMR1 43203 // 1/4 second for 5.52960MHz
// (1/5.53M) x 43203 x 128

#define TurnOnTime 300 // in seconds

//VARIABLES
int TIMER0_overflow;
int TIMER1_overflow;

//Prototype
void LEDDrive(int x);

//Interrupts
#pragma interrupt
void isr_Timer0(void)
{
DI(); //disable interrupt
TIMER0_overflow = 1;
EI(); //enable interrupt
}

#pragma interrupt
void isr_Timer1(void)
{
DI(); //disable interrupt
TIMER1_overflow = 1;
EI(); //enable interrupt
}

//Inititalizations
void init(void)
{
//Oscillator options
OSCCTL = 0xE7;
OSCCTL = 0x18;
OSCCTL = 0x80; //Internal Oscillator, 5.53MHz

//TIMER 0 options; //From Sis Paranz Tutorials.

DI(); //disable interrupt
T0CTL1 &= ~0x80; //disable Timer 0
T0CTL1 |= (0x07 << 3) | 0x01; //prescaler = 128 //continuous mode
T0H = 0x00; //initial value is 1
T0L = 0x01; //Timer 0 increments from 1 to 65535
T0RH = (OverflowValueTMR0 >> 8); //RELOAD value loaded
T0RL = (OverflowValueTMR0 & ~0xFF00);
SET_VECTOR(TIMER0, isr_Timer0); //when TIMER0 interrupt occurs, tell //CPU to execute the isr_TIMER0 ISR
IRQ0ENH |= 0x20; //enable Timer 0 interrupt with
IRQ0ENL |= 0x20; //LEVEL 3 priority
IRQ0 &= ~0x20; //clear previous/pending TIMER0 int
T0CTL1 |= 0x80; //enable timer 0
EI(); //enable interrupt

//TIMER 1 options; //From Sis Paranz Tutorials.

DI(); //disable interrupt
T1CTL1 &= ~0x80; //disable Timer 0
T1CTL1 |= (0x07 << 3) | 0x01; //prescaler = 128 //continuous mode
T1H = 0x00; //initial value is 1
T1L = 0x01; //Timer 0 increments from 1 to 65535
T1RH = (OverflowValueTMR1 >> 8); //RELOAD value loaded
T1RL = (OverflowValueTMR1 & ~0xFF00);
SET_VECTOR(TIMER1, isr_Timer1); //when TIMER0 interrupt occurs, tell //CPU to execute the isr_TIMER0 ISR
IRQ0ENH |= 0x40; //enable Timer 1 interrupt with
IRQ0ENL |= 0x40; //LEVEL 2 priority
IRQ0 &= ~0x40; //clear previous/pending TIMER1 int
T1CTL1 |= 0x80; //enable timer 1
EI(); //enable interrupt

//LED Drive Initialize
PCDD &= 0x0F; // port C[3:0] is output
PCAF |= 0x0F; // Port C alternate function is enabled
PCADDR = 0x07; // Alternate Function Set 1 = LED direct Drive
PCCTL |= 0x0F;
LEDEN |= 0x0F;

//OverRide switch init
PBDD |= 0x01; //PBDD = PBDD | 0b00000001 = PBDD |= 0x01
PBAF &= ~0x01; //PBAF = PBAF & 0b11111100

//Relay driver init
PBDD &= ~0x02; //PBDD = PBDD & 0b11111101 = PBDD &= 0xFD
PBAF &= ~0x02;
PBOC &= ~0x02;
PBHDE |= 0x02;
PBOUT &= ~0x02; //PBOUT = PBOUT & 0b11111101


}


void main()
{
int i = 0;
int j = 0;
unsigned char OverRide;
init();
while(1)
{
//OverRide
OverRide = PBIN & 0x01; //Read PBDD.0
if (OverRide == 0x00)
{
LEDEN &= 0x00; //Disable LED Drive
PBOUT |= 0x02; //Set Relay pin HIGH
T0CTL1 &= ~0x80; //Disable TIMER0
T1CTL1 &= ~0x80; //Disable TIMER1
}

else if( OverRide == 0x01)
{
//Direct LED Drive
if (TIMER0_overflow)
{
TIMER0_overflow = 0; //Reset Timer0 overflow Flag
i++;
if (i > 17) i = 0;
LEDDrive(i);
}

//Delay
if (TIMER1_overflow)
{
TIMER1_overflow = 0; //Reset Timer1 overflow Flag
j++;
if(j == TurnOnTime) //shuts down after TurnOnTime
{
T0CTL1 &= ~0x80; //Disable Timer0
LEDEN &= 0x00; //Disable LED Drive
PBOUT |= 0x02; //Set Relay pin HIGH
}
}
}
}
}



void LEDDrive(int x)
{
switch (x)
{
case 0:
LEDLVLH = 0x01;
LEDLVLL = 0x01;
break;

case 1:
LEDLVLH = 0x01;
LEDLVLL = 0x02;
break;

case 2:
LEDLVLH = 0x02;
LEDLVLL = 0x01;
break;

case 3:
LEDLVLH = 0x02;
LEDLVLL = 0x02;
break;

case 4:
LEDLVLH = 0x02;
LEDLVLL = 0x04;
break;

case 5:
LEDLVLH = 0x04;
LEDLVLL = 0x02;
break;

case 6:
LEDLVLH = 0x04;
LEDLVLL = 0x04;
break;

case 7:
LEDLVLH = 0x04;
LEDLVLL = 0x08;
break;

case 8:
LEDLVLH = 0x08;
LEDLVLL = 0x04;
break;

case 9:
LEDLVLH = 0x08;
LEDLVLL = 0x08;
break;

case 10:
LEDLVLH = 0x08;
LEDLVLL = 0x04;
break;

case 11:
LEDLVLH = 0x04;
LEDLVLL = 0x08;
break;

case 12:
LEDLVLH = 0x04;
LEDLVLL = 0x04;
break;

case 13:
LEDLVLH = 0x04;
LEDLVLL = 0x02;
break;

case 14:
LEDLVLH = 0x02;
LEDLVLL = 0x04;
break;

case 15:
LEDLVLH = 0x02;
LEDLVLL = 0x02;
break;

case 16:
LEDLVLH = 0x02;
LEDLVLL = 0x01;
break;

case 17:
LEDLVLH = 0x01;
LEDLVLL = 0x02;
break;

}

}



The schematic:
[CLICK IT!]


Some Pics of the Prototype:
Nakakatawa yang transformer.... may brand palang "tamagawa". di ba may brand na YOKOGAWA??!


the beneath, showing the procie and the voltage regulator and the not good soldering. Yang maraming LEAD, in preparation sa heavy load ng Aircon.


Bukas, nasa kahon na yan... hehehe Grin Grin Grin


Sana kayanin ng RELAY ang AirCon!


Once again, nothing special! but just to inspire...

Salamat sir Paranz. datasheet at compiled tutorial mo lang ang references ko! heheh Grin

related link: http://www.electronicslab.ph/forum/index.php?topic=11028.0
Logged

"Don't take life seriously. After all, no one has ever come out of it alive. -Bugs Bunny"
The Philippine Electronics and Technology Forum
« on: August 25, 2009, 11:21:46 PM »

 Logged
tiktak
Gas Turbine
**

Pogi/Ganda Points: 180
Offline Offline

Gender: Male
Posts: 2598



WWW
« Reply #1 on: August 25, 2009, 11:36:08 PM »

overkill nga sister Cheesy nice one
Logged

Bakit andaming hindi marunong gumamit ng search?Huh
The Philippine Electronics and Technology Forum
« Reply #1 on: August 25, 2009, 11:36:08 PM »

 Logged
marcelino
Moderator
Solar Power Satellite
*****

Pogi/Ganda Points: 256
Offline Offline

Posts: 5958


...keep moving forward! - Robinson's


« Reply #2 on: August 25, 2009, 11:42:06 PM »

^
hehehe....

ipinapakita din dito ang fast prototyping kapag MCU ang gagamitin! Grin Grin
Logged

"Don't take life seriously. After all, no one has ever come out of it alive. -Bugs Bunny"
The Philippine Electronics and Technology Forum
« Reply #2 on: August 25, 2009, 11:42:06 PM »

 Logged
rdpzycho
Technical People
Solar Power Satellite
*****

Pogi/Ganda Points: 512
Offline Offline

Gender: Male
Posts: 9583


Perfection is an Illusion


WWW
« Reply #3 on: August 26, 2009, 12:00:35 AM »

sis marce pwede ka pang magdagdag ng features like for an hour 20 minutes lang nakasindi 'yung aircon then next hour na ulit. alam ko nagkaroon ng ganitong project sa electronic enthusiast. Grin distributed kasi 'yung on time nung aircon rather than ilang oras tapos puro fan na lang. Grin same concept nung sa REF na pinapatay sindi for minutes sa gabi. huwag lang masyadong magkakalapit ang intervals dahil sira naman ang compressor.
Logged

‎"Divide each difficulty into as many parts as is feasible and necessary to resolve it."
- Rene Descartes

‎"Keep on starting, and finishing will take care of itself."
- Neil Fiore
marcelino
Moderator
Solar Power Satellite
*****

Pogi/Ganda Points: 256
Offline Offline

Posts: 5958


...keep moving forward! - Robinson's


« Reply #4 on: August 26, 2009, 12:29:26 AM »

sis marce pwede ka pang magdagdag ng features like for an hour 20 minutes lang nakasindi 'yung aircon then next hour na ulit. alam ko nagkaroon ng ganitong project sa electronic enthusiast. Grin distributed kasi 'yung on time nung aircon rather than ilang oras tapos puro fan na lang. Grin same concept nung sa REF na pinapatay sindi for minutes sa gabi. huwag lang masyadong magkakalapit ang intervals dahil sira naman ang compressor.

heheheh.... Grin Grin Grin

medyo naisip ko yan nung habang nageetch na ako!

to make it simplier, I was thinking of putting some DIP switches. each switch stands for a solution. parang set na.... para ba mas madali! makokomplicate kasi kung may interface pa. whereas, di naman laging gagalawin yan.

pwede naman siguro, sa version 2. may mangilan-ngilan pa naman akong processors dito! hehehe Grin

medyo urgent lang kasi to. panay kasi ang brownout ngayon dito at bumabalik kaagad! one month palang yung aircon namin baka masira kaagad. though under warranty, mainit naman matulog pag-gabi!
Logged

"Don't take life seriously. After all, no one has ever come out of it alive. -Bugs Bunny"
insomartin
Guest
« Reply #5 on: August 26, 2009, 12:37:04 AM »

ngayon ko lang nakita... it's not overkill  OVER-ENGINEERED!
i think the next best thing is to add a safety feature...  Grin
Logged
rdpzycho
Technical People
Solar Power Satellite
*****

Pogi/Ganda Points: 512
Offline Offline

Gender: Male
Posts: 9583


Perfection is an Illusion


WWW
« Reply #6 on: August 26, 2009, 12:38:10 AM »

 Grin Grin Grin
Logged

‎"Divide each difficulty into as many parts as is feasible and necessary to resolve it."
- Rene Descartes

‎"Keep on starting, and finishing will take care of itself."
- Neil Fiore
insomartin
Guest
« Reply #7 on: August 26, 2009, 12:40:26 AM »

sis marce pwede ka pang magdagdag ng features like for an hour 20 minutes lang nakasindi 'yung aircon then next hour na ulit. alam ko nagkaroon ng ganitong project sa electronic enthusiast. Grin distributed kasi 'yung on time nung aircon rather than ilang oras tapos puro fan na lang. Grin same concept nung sa REF na pinapatay sindi for minutes sa gabi. huwag lang masyadong magkakalapit ang intervals dahil sira naman ang compressor.

i did this using 555 timer kapag christmas (lights)... it simply means kung 50% duty cycle it means that 50% din yung consumption. but since may thermostat yung air con that randomly on's and off.. (ALMOST RANDOM) i got a feeling na hindi economical na mag on off... i can't explain it clearly but... wait i'll try to draw it..
Logged
marcelino
Moderator
Solar Power Satellite
*****

Pogi/Ganda Points: 256
Offline Offline

Posts: 5958


...keep moving forward! - Robinson's


« Reply #8 on: August 26, 2009, 12:45:48 AM »

ngayon ko lang nakita... it's not overkill  OVER-ENGINEERED!
i think the next best thing is to add a safety feature...  Grin

hahaha... over engineered nga ang tamang term!

perhaps, yan kasi ang available saakin. kasi naman... mga napulot ko yan eh... pati nga yun enclosure! Grin Grin Grin


safety feature Huh hmmm... can't think of one for such gadget.
Logged

"Don't take life seriously. After all, no one has ever come out of it alive. -Bugs Bunny"
rdpzycho
Technical People
Solar Power Satellite
*****

Pogi/Ganda Points: 512
Offline Offline

Gender: Male
Posts: 9583


Perfection is an Illusion


WWW
« Reply #9 on: August 26, 2009, 12:46:39 AM »

i did this using 555 timer kapag christmas (lights)... it simply means kung 50% duty cycle it means that 50% din yung consumption. but since may thermostat yung air con that randomly on's and off.. (ALMOST RANDOM) i got a feeling na hindi economical na mag on off... i can't explain it clearly but... wait i'll try to draw it..

yup. kaya ang pinaka-economical ta-timing-an talaga 'yung compressor. hehehe. inorasan ko na 'yung sa kwarto, 12 minutes (after mag-on ng compressor), nearly constant kapag ganitong panahon (mga 25 minutes patay 'yung compressor, pero kapag pinatay ko na, aabot naman ng more than 40 minutes 'yung acceptable na lamig). lalamig na 'yung kwarto, pwedeng fan na lang muna. Grin either i-detect kung kailan mag-on 'yung compressor o chambahan lang sa oras. Grin
Logged

‎"Divide each difficulty into as many parts as is feasible and necessary to resolve it."
- Rene Descartes

‎"Keep on starting, and finishing will take care of itself."
- Neil Fiore
marcelino
Moderator
Solar Power Satellite
*****

Pogi/Ganda Points: 256
Offline Offline

Posts: 5958


...keep moving forward! - Robinson's


« Reply #10 on: August 26, 2009, 12:50:14 AM »

yup. kaya ang pinaka-economical ta-timing-an talaga 'yung compressor. hehehe. inorasan ko na 'yung sa kwarto, 12 minutes (after mag-on ng compressor), nearly constant kapag ganitong panahon (mga 25 minutes patay 'yung compressor, pero kapag pinatay ko na, aabot naman ng more than 40 minutes 'yung acceptable na lamig). lalamig na 'yung kwarto, pwedeng fan na lang muna. Grin either i-detect kung kailan mag-on 'yung compressor o chambahan lang sa oras. Grin

kakailanganin palang magsampling. magkakaiba pala ang requirement ng rooms. ganitong nasa bahay lang... shared pa sa kabilang kwarto using exhaust fan.

di ba part pa to ng mga HVAC studies and researches?
Logged

"Don't take life seriously. After all, no one has ever come out of it alive. -Bugs Bunny"
rdpzycho
Technical People
Solar Power Satellite
*****

Pogi/Ganda Points: 512
Offline Offline

Gender: Male
Posts: 9583


Perfection is an Illusion


WWW
« Reply #11 on: August 26, 2009, 12:54:31 AM »

medyo ganun na nga sis. dahil nga sa thermostat nung aircon. hehehe.
Logged

‎"Divide each difficulty into as many parts as is feasible and necessary to resolve it."
- Rene Descartes

‎"Keep on starting, and finishing will take care of itself."
- Neil Fiore
marcelino
Moderator
Solar Power Satellite
*****

Pogi/Ganda Points: 256
Offline Offline

Posts: 5958


...keep moving forward! - Robinson's


« Reply #12 on: August 26, 2009, 12:59:14 AM »

medyo ganun na nga sis. dahil nga sa thermostat nung aircon. hehehe.

ang thesis ko nga sana ay HVAC application... kaso wala akong building na pwedeng malagyan ng testing. hehehe Grin
ang objective sana ay parang maanticipate na ng system ang lamig naigegenerate sa particular na oras ng araw. AI application na din...
Logged

"Don't take life seriously. After all, no one has ever come out of it alive. -Bugs Bunny"
insomartin
Guest
« Reply #13 on: August 26, 2009, 01:03:26 AM »

and... from HVAC naman magiging Climate Control... ayannnnn naah!
Logged
RaffT
Technical People
Hydroelectric
*****

Pogi/Ganda Points: 99
Offline Offline

Gender: Male
Posts: 3334


more on R-n-D


WWW
« Reply #14 on: August 26, 2009, 07:42:11 AM »

@marce

 wala bang timer0/timer1 for CCS Grin
Logged

Learning is CooL! BEAM robotics/DIY UCD180/PSP/AC wtmtr/digiESRmtr/PICkit™2 clone/SGTC/SSTC/DR-SSTC
marcelino
Moderator
Solar Power Satellite
*****

Pogi/Ganda Points: 256
Offline Offline

Posts: 5958


...keep moving forward! - Robinson's


« Reply #15 on: August 26, 2009, 09:06:37 AM »

@marce

 wala bang timer0/timer1 for CCS Grin

meron...
Logged

"Don't take life seriously. After all, no one has ever come out of it alive. -Bugs Bunny"
RaffT
Technical People
Hydroelectric
*****

Pogi/Ganda Points: 99
Offline Offline

Gender: Male
Posts: 3334


more on R-n-D


WWW
« Reply #16 on: August 26, 2009, 09:12:56 AM »

oops what I meant was wala ba katapat ang code na yan for CCS? hehe
Logged

Learning is CooL! BEAM robotics/DIY UCD180/PSP/AC wtmtr/digiESRmtr/PICkit™2 clone/SGTC/SSTC/DR-SSTC
paranz
Technical People
Nuclear Reactor
*****

Pogi/Ganda Points: 171
Offline Offline

Gender: Male
Posts: 4512


1/4W resistor specialist


« Reply #17 on: August 26, 2009, 09:23:27 AM »

nice project sis marce..

some of my students, ganito din project nila with included timer IC pero PIC ang gamit
Logged
marcelino
Moderator
Solar Power Satellite
*****

Pogi/Ganda Points: 256
Offline Offline

Posts: 5958


...keep moving forward! - Robinson's


« Reply #18 on: August 26, 2009, 10:19:56 AM »

oops what I meant was wala ba katapat ang code na yan for CCS? hehe

hehehe... tinawag kasi ako ni misis!
ayan, gumawa ako ng simple counter using timer0 and timer1 sa CCS.

di ko lang gusto kasi gumamit pa ako ng interrupt.

Code:
#include <16F877A.h>

#FUSES NOWDT,HS,NOPUT,NOPROTECT, NODEBUG, NOBROWNOUT, NOLVP, NOCPD, NOWRT

#use delay(clock=4000000)


int   TIMER0_overflow_flag;
int   TIMER1_overflow_flag;

#int_RTCC
void  RTCC_isr(void)
{
   TIMER0_overflow_flag = TRUE;
}

#int_TIMER1
void  TIMER1_isr(void)
{
   TIMER1_overflow_flag = TRUE;
}



void main()
{
   int16 timer0_count, timer1_count;    //overkill
   char t0,t1;
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_8);     //overflow every 2ms
   setup_timer_1(T1_INTERNAL|T1_DIV_BY_8);      //524ms
   
   enable_interrupts(INT_RTCC);
   enable_interrupts(INT_TIMER1);
   enable_interrupts(GLOBAL);

   set_tris_b(0x00);
   output_b(0x00);
   
   timer0_count = 0;
   timer1_count = 0;
   
   
   while(true)
   {
      if (TIMER0_overflow_flag)
      {
         TIMER0_overflow_flag = FALSE;
         timer0_count++;
         if (timer0_count == 1000)    //1000*2ms = 2 seconds
         {
            timer0_count = 0;
            output_high(PIN_B0); //OpenHatch();
         }
      }
     
      if (TIMER1_overflow_flag)
      {
         TIMER1_overflow_flag = FALSE;
         timer1_count++;
         if(timer1_count == 10)          // 2*524ms =~ 5sec
         {
            timer1_count = 0;
            output_high(PIN_B1); //LaunchMissile();
         }
      }
   }

}
Logged

"Don't take life seriously. After all, no one has ever come out of it alive. -Bugs Bunny"
marcelino
Moderator
Solar Power Satellite
*****

Pogi/Ganda Points: 256
Offline Offline

Posts: 5958


...keep moving forward! - Robinson's


« Reply #19 on: August 26, 2009, 10:22:00 AM »

nice project sis marce..

some of my students, ganito din project nila with included timer IC pero PIC ang gamit

yeah... maganda nga itong activity project. una, tangible at di masyado magastos... simple yet, mamamaster na din yun usage ng TIMERs.


Wink
Logged

"Don't take life seriously. After all, no one has ever come out of it alive. -Bugs Bunny"
The Philippine Electronics and Technology Forum
   

 Logged
Pages: [1] 2 3   Go Up
  Print  
 
Jump to:  


Related Topics
Subject Started by Replies Views Last post
Zilog ZGENPRP0100MDS
Zilog Microcontrollers
Ugin 4 1207 Last post March 25, 2008, 04:43:21 PM
by mochini77
PIC vs Atmega vs Zilog « 1 2 »
Microcontroller/Microprocessor Unit Projects and Programming
alyas 31 4495 Last post June 17, 2009, 11:14:28 AM
by rockjay0918
hello, Zilog is new 2 me and i need help...
Zilog Microcontrollers
cai 3 755 Last post July 16, 2008, 01:12:06 PM
by paranz
zilog programming
Microcontroller/Microprocessor Unit Projects and Programming
mushroom 4 1132 Last post December 13, 2010, 09:08:14 PM
by mkas18
Zilog or PIC
Zilog Microcontrollers
ayrtonshunt 1 785 Last post March 07, 2009, 09:29:15 PM
by jerzclanx
zilog vs pic
Zilog Microcontrollers
jepo 7 851 Last post October 11, 2009, 06:28:55 PM
by SpongeBob
alarm clock OVERKILL (pic naman) « 1 2 3 4 »
PIC Microcontrollers
insomartin 67 4596 Last post January 15, 2010, 05:30:15 PM
by abyssinian
Powered by MySQL Powered by PHP Powered by SMF 1.1.15 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!