Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Zilog comparator programming for battery and supercap

Status
Not open for further replies.

kct

New Member
Good day to everyone.

Currently I'm in the process of using a Zilog MCU (Z8F042A) to design a voltage comparator for comparing a voltage between a mobile phone battery with a maximum voltage of 4.2V, and a supercapacitor(s) rated at 5V. At any instant the supercapacitor's voltage is equivalent to that of the battery, the system will send a voltage to the gate of a P channel MOSFET to switch the MOSFET off. The moment the supercapacitor's voltage falls below that of the battery, the MOSFET is to be switched on again.

The problem now is, I am not so sure about programming the Zilog itself (programming has never been my strong point), not to mention the issue of whether I need to use the ADC or not. It would be great if anyone can help me out.

This is what I have so far...

Code:
#include<eZ8.h>
#include <stdio.h>
#include <sio.h>
#include <adc.h>

unsigned int VINSUP; // Voltage from Supercapacitor
unsigned int VINREF; // Voltage from Battery

void main(void)
{
   ADCCTL0 = 0xAE; // Conversion Enabled
               // Reference Buffer Disabled
               // Continuous Mode

   ADCCTL1 = 0x01; //Single Ended Buffered Input with Unity Gain

   PCDD = 0xF7; // PC3 as output and others as input
   
   PCOUT = 0xFF; // Turn off all ports

   while(1)
   {
      if ((PCIN & 0x01) == 0) // To check if PC0 is low or not
      {
         PCOUT = 0xF7;
      }
      else
      {
         PCOUT = 0xFF;
      }
}
 
You really have just the basics there. Your best bet is to check out the yahoo groups mailing list. There's sample code in the files section and people who know what they are doing. I could help with the ADC, but I've never used the comparator before.

**broken link removed**
 
Status
Not open for further replies.

Latest threads

Back
Top