Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

PULSEIN_ARDUINO UNO
Goto page 1, 2  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: 184
Location: D.F.

mexico.gif
PostPosted: Thu May 21, 2020 11:00 pm    Post subject: PULSEIN_ARDUINO UNO Reply with quote

Hello
I have an ARDUINOUNO card with 16Mhz external crystal, would this help with the Pulsein numbers? Are you made of 4 Mhz to work? I have read it help but more information is missing.
Back to top
View user's profile
Printpix52

Bascom Member



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

mexico.gif
PostPosted: Fri May 22, 2020 6:26 pm    Post subject: Reply with quote

Hello, so the library already includes a 16Mhz for arduino?


Code:
$lib "pulsein.lib"  
Back to top
View user's profile
O-Family

Bascom Expert



Joined: 23 May 2010
Posts: 172
Location: Japan

japan.gif
PostPosted: Sat May 23, 2020 2:56 am    Post subject: Reply with quote

As for the pulse width, one count of the variable value is set to about 10uS regardless of the AVR clock frequency.
The hardware timer is not used, so the accuracy is poor.
Back to top
View user's profile Visit poster's website
Printpix52

Bascom Member



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

mexico.gif
PostPosted: Sat May 23, 2020 5:20 am    Post subject: Reply with quote

Hello O_Family Thank you for your response and I understand.
I have tested it with real STK500 hardware at 4MHz it works very well and instead with arduino one with 16 Mhz I have not tested it with this card and I will tell you tomorrow.
10us @ 4Mhz It works fine.
?? us @ 16Mhz I have not tried or already includes $ lib "pulsein.lib"?
Back to top
View user's profile
Paulvk

Bascom Member



Joined: 28 Jul 2006
Posts: 1178
Location: SYDNEY

australia.gif
PostPosted: Sat May 23, 2020 5:34 am    Post subject: Reply with quote

You can change the timing I can not find the post from Mark but there is a "magic" number in the library you can change
I needed to make it faster for shorter pulses so look for "magic" in the library but first make a copy
and rename that to my pulsein or something so if you stuff up its just your copy.
Regards Paul
Back to top
View user's profile
O-Family

Bascom Expert



Joined: 23 May 2010
Posts: 172
Location: Japan

japan.gif
PostPosted: Sat May 23, 2020 6:09 am    Post subject: Reply with quote

It uses the @genus(x) routine to measure the pulse width.
@genus(x) counts the number of waits by calculating how many nanoseconds one machine language instruction takes for the AVR clock used. (Agree with Waitus command)
Therefore, this value is important because it derives the instruction clock cycle from the frequency value of the $crystal instruction.
Since it is measured by software, the error will be large in all respects.

With the additional library, you can change the timeout time for measurement and the measurement interval (initial value is 10uS).

Using a hardware timer is more effective than fine-tuning the library to improve measurement accuracy.
Back to top
View user's profile Visit poster's website
Paulvk

Bascom Member



Joined: 28 Jul 2006
Posts: 1178
Location: SYDNEY

australia.gif
PostPosted: Sat May 23, 2020 7:04 am    Post subject: Reply with quote

O-Family
Quote:
Using a hardware timer is more effective than fine-tuning the library to improve measurement accuracy.

Yes but sometimes you can not.
It has been a long time since I made the Infrared decoder so my memory was poor.
I still use the code I made as it works with every remote I have tried.
Regards Paul hope you are safe and well!
Back to top
View user's profile
Printpix52

Bascom Member



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

mexico.gif
PostPosted: Sun May 24, 2020 6:48 pm    Post subject: Reply with quote

Hello everyone!!
I made a program without error and all very well !!
To read RC signal for atmega8 @ 4Mhz
MAXIMUM = 174
AVERAGE = 145
MINIMUM = 113
Now for Arduino Uno @ 16Mhz
MAXIMUM = 193
AVERAGE = 160
MINIMUM = 126
Can someone tell me why I get different approximate values since I don't have an oscilloscope to measure RC signals.
Back to top
View user's profile
O-Family

Bascom Expert



Joined: 23 May 2010
Posts: 172
Location: Japan

japan.gif
PostPosted: Tue May 26, 2020 11:00 am    Post subject: Reply with quote

I don't understand the question.
Back to top
View user's profile Visit poster's website
Printpix52

Bascom Member



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

mexico.gif
PostPosted: Tue May 26, 2020 7:36 pm    Post subject: Reply with quote

Hi !
testing with my STK500 card ok !!
To read RC with Atmega8 @ 4Mhz with PULSEIN and values are.

MAXIMUM = 174
NEUTRO = 145
MINIMUM = 113

Code:
$regfile = "m8def.dat"
$crystal = 4000000
$hwstack=40
$swstack=16
$framesize = 32

'$sim

'Definir entradas

Config Pind.2 = Input
Ddrd.2 = 1

Config Lcdpin = Pin , E = Portc.1 , Rs = Portc.0
Config Lcdpin = Pin , Db4 = Portc.2 , Db5 = Portc.3
Config Lcdpin = Pin , Db6 = Portc.4 , Db7 = Portc.5
Config Lcdbus = 4
Config Lcd = 16x2
Cls
Cursor Off

Dim W As Word
Config Pind.2 = Input
 Locate 1 , 1
 Lcd "PROBADOR DE RC"
 Waitms 100
Do
   Pulsein W , Pind , 2 , 1
   Locate 2 , 1
   Lcd "PULSO ES " ; W ; "    "
Loop
End


Now with the ARDUINO UNO card ok!
Para leer RC con Atmega328p @ 16Mhz con PULSEIN y los valores son.

Now for Arduino Uno @ 16Mhz
MAXIMUM = 193
NEUTRO = 160
MINIMUM = 126

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

'Definir entradas
Config Pind.2 = Input
Ddrd.2 = 1


Config Lcdpin = Pin , E = Portc.1 , Rs = Portc.0
Config Lcdpin = Pin , Db4 = Portc.2 , Db5 = Portc.3
Config Lcdpin = Pin , Db6 = Portc.4 , Db7 = Portc.5
Config Lcdbus = 4
Config Lcd = 16x2
Cls
Cursor Off
Dim W As Word
Config Pind.2 = Input
 Locate 1 , 1
 Lcd "PROBADOR DE RC"
 Waitms 100
Do
   Pulsein W , Pind , 2 , 1
   Locate 2 , 1
   Lcd "PULSO ES " ; W ; "    "
Loop
End
 


Now with library $ lib "pulsein.lib"
Now for Arduino Uno @ 16Mhz
MAXIMUM = 193
NEUTRO = 160
MINIMUM = 126

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

'Definir entradas
Config Pind.2 = Input
Ddrd.2 = 1
$lib "pulsein.lib"

Config Lcdpin = Pin , E = Portc.1 , Rs = Portc.0
Config Lcdpin = Pin , Db4 = Portc.2 , Db5 = Portc.3
Config Lcdpin = Pin , Db6 = Portc.4 , Db7 = Portc.5
Config Lcdbus = 4
Config Lcd = 16x2
Cls
Cursor Off
Dim W As Word
Config Pind.2 = Input
 Locate 1 , 1
 Lcd "PROBADOR DE RC"
 Waitms 100
Do
   Pulsein W , Pind , 2 , 1
   Locate 2 , 1
   Lcd "PULSO ES " ; W ; "    "
Loop
End
 


Now we already saw all works well because different RC values come out and what are the real RC values?
Also I don't have an oscilloscope to measure RC signals.
Now and the library for what? but if the values are the same, could someone explain me?
Back to top
View user's profile
O-Family

Bascom Expert



Joined: 23 May 2010
Posts: 172
Location: Japan

japan.gif
PostPosted: Wed May 27, 2020 1:47 am    Post subject: Reply with quote

As mentioned earlier, the additional libraries are not meant to improve the accuracy of the [Pulsein] command.
Additional libraries allow you to change the measurement timeout and measurement interval.

You need to understand the help of [Pulsein].
---------------------------------------------------------------------------------------------
You can add a bitwait statement to be sure that the PULSEIN statement will wait for the start condition.
---------------------------------------------------------------------------------------------
In other words, it must be combined with the [BITWAIT] instruction to make the detection timing accurate.
If you want more accuracy, you can only use a hardware timer.
Back to top
View user's profile Visit poster's website
Printpix52

Bascom Member



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

mexico.gif
PostPosted: Thu May 28, 2020 2:11 am    Post subject: Reply with quote

Hello O_Family

First.- I have never worked in the library and it is the first time that I do.

Second.-I already read PULSEIN in help, just missing more information and also some example in the forum.

Third.-I made a test program atmega8 @ 4 Mhz with the library and we added and it marks error: 61 no idea what this means.

No sé dónde leo La Información. Ha pasado mucha Hora y investigando y nada.

Shocked Shocked

'This problem is a little difficult to explain PULSEIN and BITWAIT.

Cheers!!





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

Bascom Member



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

mexico.gif
PostPosted: Thu May 28, 2020 2:14 am    Post subject: Reply with quote

Code:
$regfile = "m8def.dat"
$crystal = 4000000
$hwstack=40
$swstack=16
$framesize = 32

'$sim

'Definir entradas

Config Pind.2 = Input
Ddrd.2 = 1

Config Lcdpin = Pin , E = Portc.1 , Rs = Portc.0
Config Lcdpin = Pin , Db4 = Portc.2 , Db5 = Portc.3
Config Lcdpin = Pin , Db6 = Portc.4 , Db7 = Portc.5
Config Lcdbus = 4
Config Lcd = 16x2
Cls
Cursor Off

$lib "pulsein.lib"
Const Cpulsein_timeout = 50000
Dim Bpulsein_delay As Byte : Bpulsein_delay = 10

Dim W As Word
Config Pind.2 = Input
 Locate 1 , 1
 Lcd "PROBADOR DE RC"
 Waitms 100
Do
   Pulsein W , Pind , 2 , 1
   Locate 2 , 1
   Lcd "PULSO ES " ; W ; "    "
Loop
End
Back to top
View user's profile
Printpix52

Bascom Member



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

mexico.gif
PostPosted: Thu May 28, 2020 6:48 am    Post subject: Reply with quote

Hello everyone!!
I already corrected the code but I do not understand what it is for.
What is the function? It no longer marks me error.


Code:
$lib "pulsein.lib"
Const Cpulsein_timeout = 0
Const Bpulsein_delay = 10


'Definir entradas

Config Pind.2 = Input
Ddrd.2 = 1

Config Lcdpin = Pin , E = Portc.1 , Rs = Portc.0
Config Lcdpin = Pin , Db4 = Portc.2 , Db5 = Portc.3
Config Lcdpin = Pin , Db6 = Portc.4 , Db7 = Portc.5
Config Lcdbus = 4
Config Lcd = 16x2
Cls
Cursor Off


Dim W As Word
Config Pind.2 = Input
 Locate 1 , 1
 Lcd "PROBADOR DE RC"
 Waitms 100
Do
   Pulsein W , Pind , 2 , 1
   Locate 2 , 1
   Lcd "PULSO ES " ; W ; "    "
Loop
End


Reading RC signal


MAXIMO=160
NEUTRO=132
MINIMO=104


Could someone explain this function to me?

Code:
$lib "pulsein.lib"
Const Cpulsein_timeout = x
Const Bpulsein_delay = xx


Good evening and greetings !!! Shocked Shocked Shocked
Back to top
View user's profile
O-Family

Bascom Expert



Joined: 23 May 2010
Posts: 172
Location: Japan

japan.gif
PostPosted: Thu May 28, 2020 11:34 am    Post subject: Reply with quote

If this does not stabilize the reading, your signal may be unstable.
The pulse width of servo motor is generally 0.8mS-2.2mS.
Code:

Do
   Bitwait Pind.2 , Reset
   Pulsein W , Pind , 2 , 1
   Locate 2 , 1
   Lcd "PULSO ES " ; W ; "    "
Loop
 
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 1, 2  Next
Page 1 of 2

 
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