1. 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.
    Dismiss Notice

Zilog comparator programming for battery and supercap

Discussion in 'Microcontrollers' started by kct, Apr 14, 2010.

  1. kct

    kct New Member

    Apr 14, 2010
    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 (text):
    #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

          if ((PCIN & 0x01) == 0) // To check if PC0 is low or not
             PCOUT = 0xF7;
             PCOUT = 0xFF;
  2. DirtyLude

    DirtyLude Well-Known Member

    Aug 5, 2003
    Toronto, Canada
    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.

    z8encore : Z8 Encore! and ZNEO MCUs from Zilog

Share This Page