Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

ARDUINO UNO_ADC_4_DIGITOS
Goto page 1, 2, 3  Next
 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-ARDUINO
View previous topic :: View next topic  
Author Message
Printpix52

Bascom Member



Joined: 18 Jun 2014
Posts: 282
Location: D.F.

mexico.gif
PostPosted: Sat Jul 11, 2020 12:32 am    Post subject: ARDUINO UNO_ADC_4_DIGITOS Reply with quote

Hello!!
I am trying to read the ADC values (1023) and translate in 2-DIGITS as an example and very simple but the values of (0000-0099) of 7 Segment works very well.
Now to expand to 4-DIGITS (1023) of 7 Segments, how could you do it?
I read help file and also some example:

Mod
Lookup

For 2-DIGITS:

Code:
Wu = W Mod / 10
Wd = W / 10
 


And for 4-DIGITS but nothing comes out.

Code:
Wu = Mod / 10
Wd = W / 10
Wc = W Mod / 100
Wm = W / 100
 



[img][/img]

Back to top
View user's profile
O-Family

Bascom Expert



Joined: 23 May 2010
Posts: 320
Location: Japan

japan.gif
PostPosted: Sat Jul 11, 2020 2:50 am    Post subject: Reply with quote

Code:

   Dim Ledbuff(4) As Byte                                   'Dynamic lighting segment data.
   Dim Temp1 As Byte
   Dim Tempw1 As Word
   Dim Tempw2 As Word
   Dim Tempw3 As Word
   Dim Templ1 As Long
   Dim Tempseg1 As Byte                                     'For segment data storage (1 digit)
   Dim Tempseg2 As Byte                                     'For segment data storage (10 digits)
   Dim Tempseg3 As Byte                                     'For segment data storage (100 digits)
   Dim Tempseg4 As Byte                                     'For segment data storage (1000 digits)

   '
   '  ---------------------------------------------------
   '  * Subroutine to convert Word value to 4-digit segment value *  (Tempw1 -> Ledbuff(1) , Ledbuff(2) , Ledbuff(3) , Ledbuff(4))
   '  ---------------------------------------------------
   '
Longseg:                                                    'For long variables.
   Tempw1 = Templ1
Wordseg:
   Tempw2 = Tempw1 / 100                                    'Extract 100's place.
   Tempw3 = Tempw2 * 100                                    'Extract 10s and 1s place.
   Tempw3 = Tempw1 - Tempw3
   '
   Temp1 = Tempw2                                           'Convert 100's place.
   Gosub Binseg                                             'Converts a binary value into a 2-digit segment code.
   Ledbuff(1) = Tempseg2
   Ledbuff(2) = Tempseg1
   Temp1 = Tempw3                                           'Converts the place between 10 and 1.
   Gosub Binseg                                             'Converts a binary value into a 2-digit segment code.
   Ledbuff(3) = Tempseg2
   Ledbuff(4) = Tempseg1
   '
   If Ledbuff(1) = &B0110_1111 Then                         'Is the fourth digit [0]?
      Ledbuff(1) = &B0000_0000                              'Blank display.
      If Ledbuff(2) = &B0110_1111 Then                      'Is the third digit [0]?
         Ledbuff(2) = &B0000_0000                           'Blank display.
         If Ledbuff(3) = &B0110_1111 Then                   'Is the second digit [0]?
            Ledbuff(3) = &B0000_0000                        'Blank display.
         End If
      End If
   End If
   Return


   '
   '  ---------------------------------------
   '  * Subroutine to convert binary value to 2 digit segment code *
   '  ---------------------------------------   (Temp1 = Binary data) (Tempseg1 = Lower segment code) (Tempaeg2 = Upper segment code)
   '
   '
Binseg:
   Tempseg2 = Makebcd(temp1)                                'Converts a binary value to a BCD (Binary coded decimal) value.
   Tempseg1 = Tempseg2 And &H0F                             'Get the lower BCD code.
   Tempseg1 = Lookup(tempseg1 , Segtab)                     'Convert numeric value to segment code.
   '
   Tempseg2 = Tempseg2 And &HF0                             'Get the upper BCD code.
   Shift Tempseg2 , Right , 4                               'Move down.
   Tempseg2 = Lookup(tempseg2 , Segtab)                     'Convert numeric value to segment code.
   Return


   End
   '
Segtab:
   Data &B0110_1111                                         '0
   Data &B0000_0110                                         '1
   Data &B1010_1011                                         '2
   Data &B1000_1111                                         '3
   Data &B1100_0110                                         '4
   Data &B1100_1101                                         '5
   Data &B1110_1101                                         '6
   Data &B0000_0111                                         '7
   Data &B1110_1111                                         '8
   Data &B1100_1111                                         '9
 


4-digit LED tachometer
http://www.ne.jp/asahi/shared/o-family/ElecRoom/AVRMCOM/RevCounter/RevCounter.html
Back to top
View user's profile Visit poster's website
Printpix52

Bascom Member



Joined: 18 Jun 2014
Posts: 282
Location: D.F.

mexico.gif
PostPosted: Sat Jul 11, 2020 6:34 am    Post subject: Reply with quote

Hola !! O_Family กก

I was watching your very professional program, what I can say for me is very difficult to understand but I will study calmly and on time.
Now I have read your Bascom manual with Japanese languages but there is no problem I translate them and each instruction I also read and understand.
I repeat I have read your Bascom manual for some time and I like your page.
Hi, let's talk about other topics ok, here is the simple and easy program it is about how to divide by 10 to add to the program.

Code:
Ddrb = 255
 Portb = 0

 Q1 Alias Portb.0
 Q2 Alias Portb.1
 Ddrd = 255
 Portd = 0


 Config Adc = Single , Prescaler = Auto , Reference = Avcc
 Start Adc



 Config Timer1 = Timer , Prescale = 256
 On Timer1 Presenta
 Enable Timer1
 Timer1 = 62500

 Dim W As Word
 Dim Wu As Byte
 Dim Wd As Byte
 Dim Cnt As Byte

 Do
  W = Getadc(0)
  W = W / 10
  If W > 99 Then
     W = 99
  End If

  Gosub Separa
  Gosub Presenta

 Loop
 End


 Separa:

 Wu = W Mod 10
 Wd = W / 10

 Return

 Presenta:

 Timer1 = 62500

 If Cnt < 2 Then
  Incr Cnt
  Else
    Cnt = 1
 End If

 If Cnt = 1 Then
  Q1 = 0 : Q2 = 1
  Portd = Lookup(wd , Tabla)
 End If

 If Cnt = 2 Then
  Q1 = 1 : Q2 = 0
  Portd = Lookup(wu , Tabla)
 End If


 Return

 Tabla:

 Data 63
 Data 6
 Data 91
 Data 79
 Data 102
 Data 109
 Data 124
 Data 7
 Data 127
 Data 103

 




For 4 digits I have to do these to control each digit.

Code:
 Q1 Alias Portb.0
 Q2 Alias Portb.1
 Q3 Alias Portb.2
 Q4 Alias Portb.3
 


Code:
 Dim W As Word
 Dim Wu As Word
 Dim Wd As Word
 Dim Wc As Word
 Dim Wm As Word
 Dim Cnt As Word
 


Code:
If Cnt < 4 Then
  Incr Cnt
  Else
    Cnt = 1
 End If

 If Cnt = 1 Then
  Q1 = 0 : Q2 = 0 : Q3 = 0 : Q4 = 1

  Portd = Lookup(wm , Tabla)
 End If

 If Cnt = 2 Then
  Q1 = 0 : Q2 = 0 : Q3 = 1 : Q4 = 0
  Portd = Lookup(wc , Tabla)
 End If

 If Cnt = 3 Then
  Q1 = 0 : Q2 = 1 : Q3 = 0 : Q4 = 0
  Portd = Lookup(wd , Tabla)
 End If

 If Cnt = 4 Then
  Q1 = 1 : Q2 = 0 : Q3 = 0 : Q4 = 0
  Portd = Lookup(wu , Tabla)
 End If


 Return
 


Now how do I make these for 4 Digits?

Code:
 Do
  W = Getadc(0)
  W = W / 10
  If W > 99 Then
     W = 99
  End If

  Gosub Separa
  Gosub Presenta

 Loop
 End


 Separa:

 Wu = W Mod 10
 Wd = W / 10
 


I have read in help but more information is missing.
Back to top
View user's profile
Printpix52

Bascom Member



Joined: 18 Jun 2014
Posts: 282
Location: D.F.

mexico.gif
PostPosted: Sat Jul 11, 2020 6:55 am    Post subject: Reply with quote

I made them like this but I distort the digits or are you wrong my program? Confused Confused Confused

Code:
 Do
  W = Getadc(0)
  If W > 9999 Then
     W = 9999
  End If

  Gosub Separa
  Gosub Presenta

 Loop
 End


 Separa:

 Wu = W Mod 1
 Wu = W / 1
 Wd = W Mod 10
 Wd = W / 10
 Wc = W Mod 100
 Wc = W / 100
 Wm = W Mod 1000
 Wm = W / 1000

 Return
Back to top
View user's profile
O-Family

Bascom Expert



Joined: 23 May 2010
Posts: 320
Location: Japan

japan.gif
PostPosted: Sat Jul 11, 2020 9:30 am    Post subject: Reply with quote

You can see the result as soon as you use the simulator!
Back to top
View user's profile Visit poster's website
Printpix52

Bascom Member



Joined: 18 Jun 2014
Posts: 282
Location: D.F.

mexico.gif
PostPosted: Sat Jul 11, 2020 7:14 pm    Post subject: Reply with quote

Hello!! O_Family !!
First I made test the ADC simulator does not count "W" nothing is at zero now the Monitor does work well if several ADC values.
This program is very rare 2.0.8.2 you have to update and tell your friend MARK.



[img][/img]


Now the waiting time works, you are also weird the time (100-1000)

Code:
 W = Getadc(0)
    Print W
    Waitms 100
 


We left the topic right now, I'm going to work with the Monitor and I'll tell you in a while.
Back to top
View user's profile
Printpix52

Bascom Member



Joined: 18 Jun 2014
Posts: 282
Location: D.F.

mexico.gif
PostPosted: Sat Jul 11, 2020 9:07 pm    Post subject: Reply with quote

When I put constant values W=89

Units = 0
Decimals = 89

Code:

    Wu = W Mod 1
    Wd = W / 1



    Print Wu
    Print Wd
 


[img][/img]
Back to top
View user's profile
Printpix52

Bascom Member



Joined: 18 Jun 2014
Posts: 282
Location: D.F.

mexico.gif
PostPosted: Sat Jul 11, 2020 9:13 pm    Post subject: Reply with quote

When I put constant values 89
Units = 9
Tenths = 8


Code:
 Wu = W Mod 10
    Wd = W / 10

    Print Wu
    Print Wd
 
Back to top
View user's profile
Printpix52

Bascom Member



Joined: 18 Jun 2014
Posts: 282
Location: D.F.

mexico.gif
PostPosted: Sat Jul 11, 2020 9:19 pm    Post subject: Reply with quote

Code:
 Const W = 1234

 Dim Wu As Word
 Dim Wd As Word
 Dim Wc As Word
 Dim Wm As Word

 Do

    'W = Getadc(0)
    Wu = W Mod 1
    Wu = W / 1
    Wd = W Mod 10
    Wd = W / 10
    Wc = W Mod 100
    Wc = W / 100
    Wm = W Mod 1000
    Wm = W / 1000


    Print Wu
    Print Wd
    Print Wc
    Print Wm


 Loop
 End

 



Question Question Question
Back to top
View user's profile
Printpix52

Bascom Member



Joined: 18 Jun 2014
Posts: 282
Location: D.F.

mexico.gif
PostPosted: Sun Jul 12, 2020 1:20 am    Post subject: Reply with quote

Do you have to appear vertical numbers like this?

1234

1
2
3
4


Be patient I am studying.
Back to top
View user's profile
O-Family

Bascom Expert



Joined: 23 May 2010
Posts: 320
Location: Japan

japan.gif
PostPosted: Sun Jul 12, 2020 1:28 am    Post subject: Reply with quote

What doesn't work?
Back to top
View user's profile Visit poster's website
Printpix52

Bascom Member



Joined: 18 Jun 2014
Posts: 282
Location: D.F.

mexico.gif
PostPosted: Sun Jul 12, 2020 2:07 am    Post subject: Reply with quote

Oh sorry if the simulator works, I was testing the external potentiometer. Brick wall Brick wall
Back to top
View user's profile
Printpix52

Bascom Member



Joined: 18 Jun 2014
Posts: 282
Location: D.F.

mexico.gif
PostPosted: Sun Jul 12, 2020 2:12 am    Post subject: Reply with quote

The simulator if it works 100% you are mistaken since it is not the same. Very Happy Very Happy
Back to top
View user's profile
O-Family

Bascom Expert



Joined: 23 May 2010
Posts: 320
Location: Japan

japan.gif
PostPosted: Sun Jul 12, 2020 2:47 am    Post subject: Reply with quote

I think your math is wrong.
This can be achieved with the following program.
However, as I suggested earlier, it is faster to save flash and faster if you divide the 4-digit number into the 2 high-order digits and the 2 low-order bytes to convert it to a BCD value.
Code:

   Dim W As Word
   Dim W1 As Word
   Dim W2 As Word
   Dim W3 As Word
   Dim W4 As Word

   W = 1234

   W1 = W / 1000                                            'W1 = 1

   W2 = W1 * 1000                                           'W2 = 1000
   W2 = W - W2                                              'W2 = 234
   W2 = W2 / 100                                            'W2 = 2

   W3 = W / 100                                             'W3 = 12
   W3 = W3 * 100                                            'W3 = 1200
   W3 = W - W3                                              'W3 = 34
   W3 = W3 / 10                                             'W3 = 3

   W4 = W / 10                                              'W4 = 123
   W4 = W4 * 10                                             'W4 = 1230
   W4 = W - W4                                              'W4 = 4

   Print W1
   Print W2
   Print W3
   Print W4
   Print


   Dim Tempstr As String * 5
   Dim Tempstr2 As String * 5

   Tempstr = Str(w)
   Tempstr = Format(tempstr , "0000")

   Tempstr2 = Mid(tempstr , 1 , 1)
   W1 = Val(tempstr2)

   Tempstr2 = Mid(tempstr , 2 , 1)
   W2 = Val(tempstr2)

   Tempstr2 = Mid(tempstr , 3 , 1)
   W3 = Val(tempstr2)

   Tempstr2 = Mid(tempstr , 4 , 1)
   W4 = Val(tempstr2)

   Print W1
   Print W2
   Print W3
   Print W4

   End
 
Back to top
View user's profile Visit poster's website
Printpix52

Bascom Member



Joined: 18 Jun 2014
Posts: 282
Location: D.F.

mexico.gif
PostPosted: Sun Jul 12, 2020 3:08 am    Post subject: Reply with quote

Sorry I'm doing them, you already won them for me, and now I understand what the simulator is for.




[img][/img]
Back to top
View user's profile
Display posts from previous:   
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-ARDUINO All times are GMT + 1 Hour
Goto page 1, 2, 3  Next
Page 1 of 3

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum