Digole
Digital Solutions
iDigole Buyer ProtectioniDigole Buyer
Protection
My shopping cart
0 Items:
Secure Checkout
Visit Our Live Auctions
Search store:
 

✨✨✨How does Digole display work?Try Display Emulate Tool ✨✨✨
Please select DHL as shipping from China due to most international flights cancels

Home : ~Project~ :

3-4 Chanel Digital Oscilloscope


In stock: no
   
Description
Feedback

Need one Digole Smart Display Module(DSDM)? buy them here

 Use any of DSDM to build a 4 channel digital oscilloscope

The diagarm of input and key pad:

Source Code: (Download: Source Code.Hex File)

/*
 * File:   DSDM 4CH Digi OSC.c
 * This sample project is 4 channels digital Oscilloscope
 * The 4 channel inputs on PA.0 to PA.3
 * the sample rates are depending on the system speed, can be adjusted from 64Mhz to 1Mhz
 * the trig channel can be channel 0,1,2,3
 * the trig type can be 0=LOW level, 1=High Level, 2=LOW to High edge, 3=High to LOW edge
 * PC.2 used as menu selection, PC.3 used as Parameter setting.
 * connect 2 2K to 10K resisters from VCC to PC.2 and PC.3 as pull up, then connect
 * 2 push buttons from PC.2 and PC.3 to Ground.
 * Author: guihongsun
 *
 * Created on July 3, 2014, 2:46 PM
 */

#include <htc.h>
#include <digole.h>
void sample(unsigned char speed, unsigned char trig_CH, unsigned char trig_Type);
void drawMenu(void);
void drawData(void);
unsigned char keyPressed(void);
void keyReleased(void);
void negativeMenu(unsigned char m);
void clearMenuBar(void);

#define SAMPLES 256    
persistent unsigned char buf[SAMPLES];
unsigned char ptr = 0;
persistent unsigned char sampleSPD, trigCH, trigType;
persistent unsigned char curMenu;
const unsigned char speeds[] = {64, 32, 16, 8, 4, 2, 1};

void main(void) {
    ANSEL = 0; //disable analog input
    ANSELH = 0;
    inst_refresh = 0;
    if (!POR) {
        sampleSPD = 64;
        trigCH = 0, trigType = 1;
    }
    POR = 1;
    curMenu = 0;
    CPU_SPD_64M();
    clearScreen(0);
    TRISA |= 0xf; //set PA0 to PA.3 as input
    TRISC |= 0B1100; //PC.2 and PC.3 used as push button input
    drawMenu();
    while (1) {
        CPU_SPD_8M();
        switch (keyPressed()) {
            case 2: //PC.2=0 pressed, move cursor
                negativeMenu(curMenu);
                if (++curMenu > 3)
                    curMenu = 0;
                negativeMenu(curMenu);
                break;
            case 1: //PC.3=0 pressed, change value
                switch (curMenu) {
                    case 0: //change speed
                        if (++sampleSPD > 6)
                            sampleSPD = 0;
                        drawMenu();
                        break;
                    case 1: //change triger chanel
                        ++trigCH;
                        trigCH &= 3;
                        drawMenu();
                        break;
                    case 2: //change triger type
                        ++trigType;
                        trigType &= 3;
                        drawMenu();
                        break;
                    case 3: //start sampling
                        clearMenuBar();
                        setColor(255);
                        drawStr(0, 0, "WAITING FOR TRIG...");
                        refreshScreen();
                        sample(speeds[sampleSPD], trigCH, trigType);
                        CPU_SPD_64M();
                        clearScreen(0);
                        drawMenu();
                        drawData();
                        break;
                }
                break;
        }
        CPU_SPD_8M();
        keyReleased();
    }
    //    CPU_SPD_16M();
}

void sample(unsigned char speed, unsigned char trig_CH, unsigned char trig_Type) {
    switch (speed) {
        case 64:
            CPU_SPD_64M();
            break;
        case 32:
            CPU_SPD_32M();
            break;
        case 16:
            CPU_SPD_16M();
            break;
        case 8:
            CPU_SPD_8M();
            break;
        case 4:
            CPU_SPD_4M();
            break;
        case 2:
            CPU_SPD_2M();
            break;
        case 1:
            CPU_SPD_1M();
            break;
    }
    switch (trig_Type) {
        case 0: //logic 0 on trig_CH
            while ((PORTA & (1 << trig_CH))); //test 0
            break;
        case 1: //logic 1 on trig_CH
            while (!(PORTA & (1 << trig_CH))); //test 1
            break;
        case 2: //logic 0 to 1 on trig_CH
            while ((PORTA & (1 << trig_CH))); //test 0
            while (!(PORTA & (1 << trig_CH))); //test 1
            break;
        case 3: //logic 1 to 0 on trig_CH
            while (!(PORTA & (1 << trig_CH))); //test 1
            while ((PORTA & (1 << trig_CH))); //test 0
            break;
    }
    ptr = 0;
    do {
        buf[ptr] = PORTA;
    } while (++ptr != 0);
    CPU_SPD_64M();
}

void drawMenu(void) {
    clearMenuBar();
    setColor(0B11111100);
    drawStr(0, 0, "SPEED");
    setColor(0B11111111);
    printDEC(speeds[sampleSPD]);
    setColor(0B11100011);
    drawStr(7, 0, "TRIGCH");
    setColor(0B11111111);
    printChar(trigCH + '0');
    setColor(0B11111);
    printString("TYPE");
    setColor(0B11111111);
    printChar(trigType + '0');
    setColor(0B11100000);
    printString("GO");
    negativeMenu(curMenu);
    refreshScreen();
}

void drawData(void) {
    unsigned char a, b;
    const unsigned char color[] = {0B11100000, 0B11100, 0B11, 0xff};
    b = (digole_screen_info.h - 8) / 4; //window hight for each chanel
    for (a = 0; a < 4; a++) {
        setColor(color[a]);
        digole_pattern = 0x55;
        drawLine(0, b + 8 + b * a - 1, digole_screen_info.w - 1, b + 8 + b * a - 1);
        digole_pattern = 0xff;
        ptr = 0;
        digole_Gx = 0;
        digole_Gy = b + b * a + 7;
        do {
            if (buf[ptr]&(1 << a))
                drawLineTo(digole_screen_info.w * ptr / SAMPLES, b * a + 8);
            else
                drawLineTo(digole_screen_info.w * ptr / SAMPLES, b + b * a + 7);
        } while (++ptr != 0);
    }
    refreshScreen();
}

void keyReleased(void) {
    while ((PORTC & 0B1100) != 0B1100); //waiting for key released
}

unsigned char keyPressed(void) {
    unsigned k;
    do {
        k = PORTC & 0B1100;
        while (k == 0B1100)k = PORTC & 0B1100; //no key pressed
        for (ptr = 0; ptr < 100; ptr++) //delay
            asm("nop");
    } while (k != (PORTC & 0B1100));
    return (k >> 2);
}

void negativeMenu(unsigned char m) {
    unsigned char t;
    const char pos[] = {0, 40, 41, 42, 84, 28, 113, 12};
    t = digole_mode;
    digole_mode = '!';
    drawBox(pos[m * 2], 0, pos[m * 2 + 1], 8);
    digole_mode = t;
    refreshScreen();
}

void clearMenuBar(void) {
    setColor(0);
    setMode('C');
    drawBox(0, 0, digole_screen_info.w - 1, 7);
}

More practice: you can try to use small font to save space on screen, add cursor and compare, use PORTB as input to sample 8bit data by using DSDM12864LCDS4/6/7.

How to install MPLAB IDE and Hi-tech C compiler
DSDM Hardware Specifications
DSDM Programmer Manual
Download "digole.h" file for MPLAB IDE and HI-TECH C

Copyright Digole Digital Solutions, 2008-2021. All rights reserved.
Powered by Digole