WiCard Timer (+Tutorial Video)

Electronics and Programming tutorials and projects

WiCard Timer (+Tutorial Video)

wicard timer 1

WiCard 32 Bit Timer

With help of my project, ESP8266 and ATmega8a (WiCard) module, you can build this timer project.

There’s a 32 bit timer counter in WiCard WiFi module. The timer calls its handler function whenever its counter reaches to 0. The unit of the timer counter is micro second (uS).

This feature in the current revision is limited. So the real time unit is 1000 uS. That means the counter value will plus 1000 every 1 mS. Also the minimum time must be set at least 500000 uS (0.5 S). We will decrease the limitation in the future revisions of the firmware.

The Functions:

  • SetTimerCounter(uiTime)

This function starts counting down uiTime value. After it reaches to zero, the system will call the handler function. When the counter reaches to zero, to enabling the timer counter again, you must call this function with its argument again.

  • TimerIntHandler()

This is the timer handler function. When the counter reaches to zero, the system will execute the source code inside of the TimerIntHandler() function. You must define this function only once.

Example:

main()
{
    SetPinsAsOutput(0x1);
    SetTimerCounter(1000000);
}

TimerIntHandler()
{
    SetPortLatch(0x1); //After 1S Pin A03 (Port Bit 0) Will Be 1
}

Tutorial Video:

The following schematic is a circuit with a 7 segment and a WiCard WiFi module. The 7 segment starts counting from 0 to 9 after toggling start/stop button.

The 7 segment in the video is “Anode Common”, So if I set a bit to “1”, the LED on 7 segment turns off. if I clear a bit to “0”, the LED on 7 segment turns on. So here’s the video::

Here’s the source code in the video:

mbToggle_0 = 0;

main()
{
    ucCounter = 0;
    SetPinsAsOutput(0x70800E);
    ControlBoxHandler();
}

ControlBoxHandler()
{
    if(mbToggle_0)
        SetTimerCounter(1000000);
}

TimerIntHandler()
{
    // ..21...
    // |     |
    // 20   22
    // |.15..|
    // |     |
    // 3     1
    // |..2..| 0

    SetPortLatch(0x70800F);

    if(ucCounter == 0)
        ClearPortLatch(0x70000E);
    else if(ucCounter == 1)
        ClearPortLatch(0x400002);
    else if(ucCounter == 2)
        ClearPortLatch(0x60800C);
    else if(ucCounter == 3)
        ClearPortLatch(0x608006);
    else if(ucCounter == 4)
        ClearPortLatch(0x508002);
    else if(ucCounter == 5)
        ClearPortLatch(0x308006);
    else if(ucCounter == 6)
        ClearPortLatch(0x30800E);
    else if(ucCounter == 7)
        ClearPortLatch(0x600002);
    else if(ucCounter == 8)
        ClearPortLatch(0x70800E);
    else
        ClearPortLatch(0x708006);

    ucCounter += 1;

    if(ucCounter == 10)
        ucCounter = 0;

    if(mbToggle_0)
        SetTimerCounter(1000000);
}

PCIntHandler()
{
    ClearPCIntRaisingFlag(0xFFFFFFFF);
    ClearPCIntFallingFlag(0xFFFFFFFF);
}

SSMIntHandler()
{
}

***””Electronics, Programming and Arduino projects, including the source codes, schematics and PCB plans for engineers, student and hobbyists””***

 

Leave a Reply

Your email address will not be published. Required fields are marked *

3 × 2 =