Hot!remove a zero

Page: 12345.. > >> Showing page 1 of 8
Author
kurt
Starting Member
  • Total Posts : 70
  • Reward points : 0
  • Joined: 2017/05/07 13:18:17
  • Location: 0
  • Status: offline
2018/01/21 04:47:30 (permalink)
0

remove a zero

 
hello,
 
i'am trying to make my multiplexing to work in real step by step on a broadbord. but i encountered something to which i don't exactly know how to solve it. underneath is  my code.   if i want to display 4564 (Temperature at the bottom)  it goes without any problem.  but if i want to display 888  i get a zero in front of it (0888)i don't want that. anyone know how  to solve this 
 
 
 
///////////////////////////////
#include "header.h"
#include <xc.h>
#include <plib.h>
#include <pic18f2220.h>
#define _XTAL_FREQ 4000000
//#include "Multiplexing-7-Segment.h"
#define Digit1 PORTCbits.RC0
#define Digit2 PORTCbits.RC1
#define Digit3 PORTCbits.RC2
#define Digit4 PORTCbits.RC3
#define punt PORTBbits.RB7
#define delay 4
void init_ADC(void);
unsigned long int ADCResult = 0;
unsigned int temperature = 0;
unsigned long int ADCSum = 0;
unsigned short int NSum = 0;
unsigned char Display(unsigned char digit)
{
unsigned char pattern;
unsigned char SEGMENT_MAP[10] = { 0x3F, 0x06, 0x5B, 0x4F, 0x66, 0x6D, 0x7D, 0x07, 0x7F, 0x6F };
pattern = SEGMENT_MAP[digit]; //The pattern to return
return (pattern);
}
void main()
{
unsigned char ASD, BSD, CSD, DSD, ESD, FSD;
unsigned int count; //, temperature;

TRISB = 0;
TRISC = 0;
OSCCON = 0x60; // Set for Internal Oscillator
init_ADC();
Digit1 = 0; //Disable digit 1
Digit2 = 0; //Disable digit 2
Digit3 = 0;
Digit4 = 0;


while (1)
{
ASD = (temperature / 1000) % 10;
LATB = Display(ASD);
Digit1 = 1;
__delay_ms(delay);
Digit1 = 0;
 
BSD = (temperature / 100) % 10;
LATB = Display(BSD);
Digit2 = 1;
__delay_ms(delay);
Digit2 = 0;
 
CSD = (temperature / 10) % 10;
LATB = Display(CSD);
Digit3 = 1;
__delay_ms(delay);
Digit3 = 0;


DSD = temperature % 10;
LATB = Display(DSD);
Digit4 = 1;
__delay_ms(delay);
Digit4 = 0;
// }
 
temperature = 888
 
 
 
 
 
#1

155 Replies Related Threads

    Gort2015
    Klaatu Barada Nikto
    • Total Posts : 2262
    • Reward points : 0
    • Joined: 2015/04/30 10:49:57
    • Location: 0
    • Status: offline
    Re: remove a zero 2018/01/21 05:29:35 (permalink)
    0
    You have to check for zero.
    Clear a flag when a non zero digit is found to stop the zero check.
     
    bool ZEROCHK=TRUE
    ::loop 4::
    check for zero?
    yes:  if(ZEROCHK) BLANK_OUT else DIGIT OUT '0'
    no: ZEROCHK=false; DIGIT OUT '1'-'9'
    ::next::
     
    I have some BCD code that does that, I'll dig it up later.
     

    MPLab X playing up, bug in your code? Nevermind, Star Trek:Discovery will be with us soon.
    https://www.youtube.com/watch?v=Iu1qa8N2ID0
    + ST:Continues, "What Ships are Made for", Q's back.
    #2
    kurt
    Starting Member
    • Total Posts : 70
    • Reward points : 0
    • Joined: 2017/05/07 13:18:17
    • Location: 0
    • Status: offline
    Re: remove a zero 2018/01/21 05:40:50 (permalink)
    0
    i think i know what you mean,  but how do i implement it in my code
    #3
    Gort2015
    Klaatu Barada Nikto
    • Total Posts : 2262
    • Reward points : 0
    • Joined: 2015/04/30 10:49:57
    • Location: 0
    • Status: offline
    Re: remove a zero 2018/01/21 05:54:55 (permalink)
    0
    If you had the number as BCD.  0x0034
     
    int BCD=0x0034;
    bool ZEROCHECK=true;
    for(int digit=0;digit<4;digit++){
        n=BCD>>12;
        BCD<<=4;
        if(n==0){
            if(ZEROCHECK)  LATB=0;          //nothing, OFF
            else LATB=SEGMENT_MAP[0];  //zero 0 digit assumming 0 - 9
        }
        else{
             ZEROCHECK=false;
             LATB=SEGMENT_MAP[n];  //assumming 0 - 9
       }
    }

    output BLANK:BLANK:3:4
    post edited by Gort2015 - 2018/01/21 06:02:19

    MPLab X playing up, bug in your code? Nevermind, Star Trek:Discovery will be with us soon.
    https://www.youtube.com/watch?v=Iu1qa8N2ID0
    + ST:Continues, "What Ships are Made for", Q's back.
    #4
    1and0
    Access is Denied
    • Total Posts : 7748
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: remove a zero 2018/01/21 06:17:04 (permalink)
    0
    Replace
    LATB = Display(ASD);

    with
    if (ASD)
        LATB = Display(ASD);
    else
        LATB = 0x00;


    Replace
    LATB = Display(BSD);

    with
    if (BSD || LATB)
        LATB = Display(BSD);

     
    Replace this
    LATB = Display(CSD);

    with
    if (CSD || LATB)
        LATB = Display(CSD);

    #5
    kurt
    Starting Member
    • Total Posts : 70
    • Reward points : 0
    • Joined: 2017/05/07 13:18:17
    • Location: 0
    • Status: offline
    Re: remove a zero 2018/01/21 06:59:30 (permalink)
    0
     
     
    you do not need to do this because this is first digit, right?
    can you explain me this piece of code "if (BSD || LATB)" that you use 
     
    almost forgot   thanks
     
     
    #6
    bblessing
    Super Member
    • Total Posts : 648
    • Reward points : 0
    • Joined: 2008/12/04 06:44:21
    • Location: Cincinnati, OH
    • Status: online
    Re: remove a zero 2018/01/21 07:03:07 (permalink)
    0
    You might also want to swing by the Embedded Gurus website and check out their piece on using the modulus operator. They have a routine that should make what you're trying to do faster, as the modulus operator is expensive.
    #7
    Gort2015
    Klaatu Barada Nikto
    • Total Posts : 2262
    • Reward points : 0
    • Joined: 2015/04/30 10:49:57
    • Location: 0
    • Status: offline
    Re: remove a zero 2018/01/21 07:40:31 (permalink)
    0
    ***4
    **34
    *234
    1234
     
    Where * = off.
     
     
    ***0 zero
     
     

    MPLab X playing up, bug in your code? Nevermind, Star Trek:Discovery will be with us soon.
    https://www.youtube.com/watch?v=Iu1qa8N2ID0
    + ST:Continues, "What Ships are Made for", Q's back.
    #8
    kurt
    Starting Member
    • Total Posts : 70
    • Reward points : 0
    • Joined: 2017/05/07 13:18:17
    • Location: 0
    • Status: offline
    Re: remove a zero 2018/01/21 11:22:28 (permalink)
    0
    it works
    #9
    1and0
    Access is Denied
    • Total Posts : 7748
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: remove a zero 2018/01/21 12:58:46 (permalink)
    0
    kurt
    you do not need to do this because this is first digit, right?
    can you explain me this piece of code "if (BSD || LATB)" that you use 

    What you are trying to do is to remove (or blank out) the leading zeros of a displayed number. So, if the most significant digit is zero, you want it blank. Then you have to determine the following digits are still leading zeros or not; and blank it out if it is. Of course, the one's digit will always be displayed, even if it's zero.
     
    The test
    if (BSD || LATB)

    is the same as
    if ((BSD != 0) || (LATB != 0x00))

    It checks to see if the current digit is non-zero and display it if it's 1 to 9. It also check to see if the previous digit written to LATB is not a blank and display 0 if it's not a leading zero. In other words, this if() statement checks to see if the current digit is zero, and if it is then check to see if the previous digit is blank, and if it is then keep the digit as blank (leading zero) by not updating LATB; otherwise, output the current digit to LATB.
    #10
    kurt
    Starting Member
    • Total Posts : 70
    • Reward points : 0
    • Joined: 2017/05/07 13:18:17
    • Location: 0
    • Status: offline
    Re: remove a zero 2018/01/21 14:08:35 (permalink)
    0
    thats clear,  
    another issue i encountered is,  i call it "flikkering" or something.  sometimes for instance if the value is between
    22 and 23 the digits start to flikker by displaying 22 and 0.01 seconds later to 23 and 0.01 second later back to 22 and 0.01 second later back again to 23.  this happens so fast that i can see both values.  now i can insert  a delay function but this is going to affect my multiplexing. any tips for this 
    #11
    qɥb
    Monolothic Member
    • Total Posts : 2058
    • Reward points : 0
    • Joined: 2017/09/09 05:07:30
    • Location: Jupiter
    • Status: offline
    Re: remove a zero 2018/01/21 14:13:41 (permalink)
    0
    There's a few approaches.
    [1] Do a running average on the signal, which will slow down changes.
    [2] Add some "hysteresis". i.e. save the number you are currently displaying, and only update the value if the new value is different by more than one.
     

    PicForum "it just works"
    #12
    Gort2015
    Klaatu Barada Nikto
    • Total Posts : 2262
    • Reward points : 0
    • Joined: 2015/04/30 10:49:57
    • Location: 0
    • Status: offline
    Re: remove a zero 2018/01/21 15:33:40 (permalink)
    0
    A timed interrupt can be used to refresh the digits since they are multiplexed.
    That way you get no flickering.
     
    If the update is random then you will get flickering.  The timing must be equal.
     
    A better method that does not involve the mpu constanting refreshing is to use a device such as the Maxim Integrated MAX7219/MAX7221 which does all the refreshing and can handle 8 digits.
     
     
     
     

    MPLab X playing up, bug in your code? Nevermind, Star Trek:Discovery will be with us soon.
    https://www.youtube.com/watch?v=Iu1qa8N2ID0
    + ST:Continues, "What Ships are Made for", Q's back.
    #13
    Gort2015
    Klaatu Barada Nikto
    • Total Posts : 2262
    • Reward points : 0
    • Joined: 2015/04/30 10:49:57
    • Location: 0
    • Status: offline
    Re: remove a zero 2018/01/21 15:42:50 (permalink)
    0
    Field of perception, no delays between digits.
    One digit is written, it will start to fade when it is turned off and the next turned on.
     
    You have to write all digits really fast to overcome that fade.

    MPLab X playing up, bug in your code? Nevermind, Star Trek:Discovery will be with us soon.
    https://www.youtube.com/watch?v=Iu1qa8N2ID0
    + ST:Continues, "What Ships are Made for", Q's back.
    #14
    1and0
    Access is Denied
    • Total Posts : 7748
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: remove a zero 2018/01/21 15:48:26 (permalink)
    +1 (1)
    Gort2015
    A timed interrupt can be used to refresh the digits since they are multiplexed.
    That way you get no flickering.

    I don't think so.  OP's new issue is the reading is oscillating back and forth between two readings.  Qub provided the solution.
     
    #15
    Gort2015
    Klaatu Barada Nikto
    • Total Posts : 2262
    • Reward points : 0
    • Joined: 2015/04/30 10:49:57
    • Location: 0
    • Status: offline
    Re: remove a zero 2018/01/21 15:57:59 (permalink)
    0
    See how that goes then.
     
    A 4 BCD buffer contains the digit values.
    D1 on, write
    D2 on, write
    D3 on, write
    D4 on, write
     
    That is what multiplexing is.  I have done that, I know what the o/p is trying to do.

    MPLab X playing up, bug in your code? Nevermind, Star Trek:Discovery will be with us soon.
    https://www.youtube.com/watch?v=Iu1qa8N2ID0
    + ST:Continues, "What Ships are Made for", Q's back.
    #16
    Gort2015
    Klaatu Barada Nikto
    • Total Posts : 2262
    • Reward points : 0
    • Joined: 2015/04/30 10:49:57
    • Location: 0
    • Status: offline
    Re: remove a zero 2018/01/21 16:06:38 (permalink)
    0
    I've also used the chips I mentioned that can do 800Hz for 8 digits.

    MPLab X playing up, bug in your code? Nevermind, Star Trek:Discovery will be with us soon.
    https://www.youtube.com/watch?v=Iu1qa8N2ID0
    + ST:Continues, "What Ships are Made for", Q's back.
    #17
    1and0
    Access is Denied
    • Total Posts : 7748
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: remove a zero 2018/01/21 16:11:01 (permalink)
    0
    I know what multiplexing is too.  OP's issue is read a value, display it, read another value, display it, etc.  If the value is between two readings, like in an ADC where the voltage is between two levels or due to noises, he will see the display oscillating between these two readings.
     
    #18
    Gort2015
    Klaatu Barada Nikto
    • Total Posts : 2262
    • Reward points : 0
    • Joined: 2015/04/30 10:49:57
    • Location: 0
    • Status: offline
    Re: remove a zero 2018/01/21 16:15:04 (permalink)
    0
    Set a 1 second delay between updating the values. (not the scan)
    There is only a certain amount the eye can retain like when you move you head quickly from left to right.
    You never see what is inbetween.
    post edited by Gort2015 - 2018/01/21 16:17:17

    MPLab X playing up, bug in your code? Nevermind, Star Trek:Discovery will be with us soon.
    https://www.youtube.com/watch?v=Iu1qa8N2ID0
    + ST:Continues, "What Ships are Made for", Q's back.
    #19
    1and0
    Access is Denied
    • Total Posts : 7748
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: remove a zero 2018/01/21 16:23:33 (permalink)
    +1 (1)
    Gort2015
    Set a 1 second delay between updating the values. (not the scan)
    There is only a certain amount the eye can retain like when you move you head quickly from left to right.
    You never see what is inbetween.

    Yes, that can be added as [3] to Qub's list of approaches. ;)
     
    #20
    Page: 12345.. > >> Showing page 1 of 8
    Jump to:
    © 2018 APG vNext Commercial Version 4.5