Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

ARDUINO UNO_ADC_4_DIGITOS
Goto page Previous  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: 226
Location: D.F.

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

Now I understand all the pure logic, friend. I am going to test your program and I will tell you tomorrow because it is already very nights.
Good night!!
Smile Smile
Back to top
View user's profile
O-Family

Bascom Expert



Joined: 23 May 2010
Posts: 182
Location: Japan

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

I was able to understand the method you want to achieve.
It's a programming mistake.
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 = W Mod 1000                                          'W2 = 234
   W2 = W2 / 100                                            'W2 = 2

   W3 = W Mod 100                                           'W3 = 34
   W3 = W3 / 10                                             'W3 = 3

   W4 = W Mod 10                                            'W4 = 4

   Print W1
   Print W2
   Print W3
   Print W4
   Print

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

Bascom Member



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

mexico.gif
PostPosted: Sun Jul 12, 2020 7:12 pm    Post subject: Reply with quote

Hi!! O_Family!!

Now if I already understand all of them, it is pure logic and mathematics.
All three simulator of yours works fine now I am going to test external card.
Back to top
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5070
Location: Holland

blank.gif
PostPosted: Mon Jul 13, 2020 9:57 am    Post subject: Reply with quote

also have a look at STR2DIGITS function.
_________________
Mark
Back to top
View user's profile Visit poster's website
O-Family

Bascom Expert



Joined: 23 May 2010
Posts: 182
Location: Japan

japan.gif
PostPosted: Mon Jul 13, 2020 1:11 pm    Post subject: Reply with quote

Hello, Mark
I overlooked this wonderful function.
Recent additions?
I'll add it to my manual now!
Back to top
View user's profile Visit poster's website
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5070
Location: Holland

blank.gif
PostPosted: Mon Jul 13, 2020 1:42 pm    Post subject: Reply with quote

i think it exist some time. since version 2.0.5.0
_________________
Mark
Back to top
View user's profile Visit poster's website
Printpix52

Bascom Member



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

mexico.gif
PostPosted: Mon Jul 13, 2020 7:39 pm    Post subject: Reply with quote

Hello everyone the World !!
I already learned them very well mathematically and logically and the simulator works very well.

[img][/img]

Razz Razz
Back to top
View user's profile
Printpix52

Bascom Member



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

mexico.gif
PostPosted: Mon Jul 13, 2020 7:58 pm    Post subject: Reply with quote

At the time of connecting with the digits it works and gives values 0-1023 but there are some digits are weak and others are not, why is it? My card is fine.
Sad

DIGITO___1 _Low_Led
DIGITO___0 _High_Led___OK!!
DIGITO___2_ Low_Led
DIGITO___3_High_Led___OK!!

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

Bascom Member



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

mexico.gif
PostPosted: Mon Jul 13, 2020 10:37 pm    Post subject: Reply with quote

I did a test for 4 digits all work well then what will it be? Is it not a faulty program or is it not compatible on port D? Question Question


Code:
$regfile = "m328pdef.dat"
$crystal = 16000000
$hwstack = 40
$swstack = 16
$framesize = 32


'CtrL

 Ddrb.0 = 1
 Portb.0 = 1
 Ddrb.1 = 1
 Portb.1 = 1
 Ddrb.2 = 1
 Portb.2 = 1
 Ddrb.3 = 1
 Portb.3 = 1

'Segmento display

 Ddrd = 255
 Portd = 0

Segmento Alias Portd

Dim I As Byte


Do
  For I = 0 To 15
   Segmento = Lookup(i , Tabla)
   Waitms 1000
  Next I

  For I = 15 To 0 Step -1
   Segmento = Lookup(i , Tabla)
   Waitms 1000
  Next I
Loop
End


'Catodo Comun

Tabla:

 Data 63
 Data 6
 Data 91
 Data 79
 Data 102
 Data 109
 Data 124
 Data 7
 Data 127
 Data 103
 Data 119
 Data 124
 Data 57
 Data 94
 Data 121
 Data 113
Back to top
View user's profile
Printpix52

Bascom Member



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

mexico.gif
PostPosted: Tue Jul 14, 2020 12:27 am    Post subject: Reply with quote

Isn't this a program? There are no other ways?

1234

4
3
2
1


Code:
Dim W1 As Word
Dim W2 As Word
Dim W3 As Word
Dim W4 As Word
Dim Wx As Word
Dim Wy As Word



Const W = 1234


Do

 Print "W= " ; W

 W1 = W Mod 10
 Print "W1= " ; W1
 Wx = W / 10
 Print "Wx= " ; Wx
 W2 = Wx Mod 10
 Print "W2= " ; W2
 Wy = Wx / 10
 Print "Wy= " ; Wy
 W3 = Wy Mod 10
 Print "W3= " ; W3
 W4 = Wy / 10
 Print "W4= " ; W4

Loop
End

 
Back to top
View user's profile
Printpix52

Bascom Member



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

mexico.gif
PostPosted: Tue Jul 14, 2020 12:30 am    Post subject: Reply with quote

Are you ok or wrong?

Code:
$regfile = "m328pdef.dat"
$crystal = 16000000
$hwstack=40
$swstack=16
$framesize=32


 Ddrb = 255
 Portb = 0



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

 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 W1 As Word
 Dim W2 As Word
 Dim W3 As Word
 Dim W4 As Word
 Dim Wx As Word
 Dim Wy As Word

 Dim Cnt As Word

 Do
  W = Getadc(0)
   W = W

  If W > 9999 Then
     W = 1023

  End If

  Gosub Separa
  Gosub Presenta

 Loop
 End


 Separa:

 W1 = W Mod 10
 Wx = W / 10
 W2 = Wx Mod 10
 Wy = Wx / 10
 W3 = Wy Mod 10
 W4 = Wy / 10





 Presenta:

 Timer1 = 62500

 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(w4 , Tabla)
 End If

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

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

 If Cnt = 4 Then
  Q1 = 1 : Q2 = 0 : Q3 = 0 : Q4 = 0
  Portd = Lookup(w1 , 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
Back to top
View user's profile
O-Family

Bascom Expert



Joined: 23 May 2010
Posts: 182
Location: Japan

japan.gif
PostPosted: Tue Jul 14, 2020 1:56 am    Post subject: Reply with quote

When LEDs are dynamically lit (pulse lit) (duty lit), if the display time for each digit is not constant, the light and shade will appear for each digit.
Normally, a periodic interrupt is used to light each digit sequentially with a pulse for a certain period.
Earlier, I told you that if you turn on the light while doing the calculation in the main routine like you, there will be a problem with the processing time, but that is the result.

In addition, when using dynamic lighting, it is necessary to turn off the common signal for each digit, change the segment data, and turn on the common signal.
This blanking period prevents the ghost phenomenon that affects the display of adjacent digits.
Back to top
View user's profile Visit poster's website
enniom

Bascom Member



Joined: 20 Oct 2009
Posts: 474

PostPosted: Tue Jul 14, 2020 3:55 am    Post subject: Reply with quote

An alternative to STR2DIGITS.

Code:
$sim

Dim I As Byte , W As Word , Digit As Byte
Dim St_w As String * 6
Dim Wd(5) As Byte At St_w Overlay

W = 12034
St_w = Str(w)

For I = 1 To 5
    Digit = Wd(i) - 48
    Print Digit
Next

End

E
Back to top
View user's profile
Printpix52

Bascom Member



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

mexico.gif
PostPosted: Tue Jul 14, 2020 6:25 am    Post subject: Reply with quote

O-Family wrote:
When LEDs are dynamically lit (pulse lit) (duty lit), if the display time for each digit is not constant, the light and shade will appear for each digit.
Normally, a periodic interrupt is used to light each digit sequentially with a pulse for a certain period.
Earlier, I told you that if you turn on the light while doing the calculation in the main routine like you, there will be a problem with the processing time, but that is the result.

In addition, when using dynamic lighting, it is necessary to turn off the common signal for each digit, change the segment data, and turn on the common signal.
This blanking period prevents the ghost phenomenon that affects the display of adjacent digits.


Thanks Friend O_Family.
I was reading the calculation of the timer, all of them are fine, for me I lack many to study this topic, I am going to study in your tutorial with time and calm.
I already found the flaws you were the program but it works very well since you turn on the 4 digits and I am very happy.
Anyway I already learned the Mod and Lookup instructions how it works ok.
The 4 digits already works very well.

Code:
If Cnt < 5 Then
   Cnt = Cnt + 1
  Else
   Cnt = 1
 End If


Back to top
View user's profile
EDC

Bascom Expert



Joined: 26 Mar 2014
Posts: 693

poland.gif
PostPosted: Tue Jul 14, 2020 6:29 am    Post subject: Reply with quote

For 7SEG LED displays multiplexing you should have 50Hz for each display so for four of them you should calc 4x50Hz=200Hz.

Now look for your speed -> 16MHz/256=62500Hz Now 16bit Timer1 65536-62500=3036. So 62500Hz/3036=20Hz ONLY Crying or Very sad

For 200Hz you should use Prescaler = 2 and Timer1 = 25536

Second thing. Instead this code:
Code:
Presenta:

 Timer1 = 62500

 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(w4 , Tabla)
 End If

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

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

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


Use something like this:
Code:

Presenta:

 Timer1 = 25536                                             'remember Prescale = 2

 Incr Cnt : If Cnt > 4 Then Cnt = 1

 Select Case Cnt
  Case 1
     Q1 = 0
    Portd = Lookup(w4 , Tabla)
     Q4 = 1
  Case 2
     Q4 = 0
    Portd = Lookup(w3 , Tabla)
     Q3 = 1
  Case 3
     Q3 = 0
    Portd = Lookup(w2 , Tabla)
     Q2 = 1
  Case 4
     Q2 = 0
    Portd = Lookup(w1 , Tabla)
     Q1 = 1
 End Select

 Return


Last edited by EDC on Tue Jul 14, 2020 6:36 am; edited 1 time in total
Back to top
View user's profile Visit poster's website
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 Previous  1, 2, 3  Next
Page 2 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