Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

htrc110 change frequency
Goto page 1, 2  Next
 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR
View previous topic :: View next topic  
Author Message
protoncek

Bascom Member



Joined: 16 May 2011
Posts: 52
Location: Slovenia

slovenia.gif
PostPosted: Fri Jan 01, 2021 7:41 pm    Post subject: htrc110 change frequency Reply with quote

Hello to all any happy new year 2021!

I have a question: i'm working with HTRC110 and demo code works quite well on my Mega8515, running at 8MHz. Now i'd like to change this to 16MHz. For this to work i have to change FSEL0 and FSEL1 both to 1. I opened library htrc110.lbx in notepad++ and changed:
Quote:
.equ Tag_set_config_page3 = &H40 + 48 + Fsel0 ' 8 Mhz

to
Quote:
.equ Tag_set_config_page3 = &H40 + 48 + Fsel0 + Fsel1 ' 16 Mhz


and of course it doesn't work (i wish it was that simple...) It seems that bascom doesn't send corrected initial config into HTRC chip.

Mega8515 has option to drive external devices with 16MHz frequency via XTAL2 output, so i connected it to HTRC. But freq. selection doesn't change in HTRC, because coil now runs at 250kHz.

What am i doing wrong? I'd like to run my mega on 16MHz and use that clock for HTRC, so it's necesarry to change config_page_3. Is there any way to send config manually? I don't find any info regarding this...

Clock source itself works, since HTRC coil runs at dobule frequency, so i guess that only mistake is that it doesn't get correct config...¸

Is it ok to run my code together with this RFID reader code (it's around 6kb) - will my code be intrusive for hitag reder too much? Or is it better to have two mega's: one just for rfid reading and other for my program?

(the reason i'm using m8515 is because i have a whole bunch of them, so it wouldn't be a problem to have two in my project...)


Thanks!

(BASCOM-AVR version : 2.0.8.3 )
Back to top
View user's profile Visit poster's website
MWS

Bascom Member



Joined: 22 Aug 2009
Posts: 2262

blank.gif
PostPosted: Sat Jan 02, 2021 3:58 pm    Post subject: Re: htrc110 change frequency Reply with quote

protoncek wrote:
and changed:
Code:
.equ Tag_set_config_page3 = &H40 + 48 + Fsel0                          ' 8 Mhz

The .EQU is likely not used, you can check it by looking the .lbx up for Tag_set_config_page3, it's declared but nowhere used.
Second, renaming Tag_set_config_page3 to ...page3_ obviously would throw an error, as the compiler does not like a required constant to be missing.

May as well look like some work for Mark.

Quote:
Is there any way to send config manually? I don't find any info regarding this...

SPIOUT on the Config HITAG's DIN/CLOCK pins may work for banging the command out, data sheet tells:
Quote:
All commands are transmitted to the HTRC110 serial interface starting with Most Significant Bit (MSB). DIN and DOUT are valid when SCLK is high.

It can be done with a few lines of code too, maybe easier if you're not sure about polarity.
Disable interrupt while banging data in and clear IntFlag after, in case Interrupt is used.
Back to top
View user's profile
protoncek

Bascom Member



Joined: 16 May 2011
Posts: 52
Location: Slovenia

slovenia.gif
PostPosted: Sat Jan 02, 2021 4:44 pm    Post subject: Reply with quote

Yes, i feared so... i don’t know much about assembler, but i noticed only one entry of page3, too. So i guess you’re right, it’s never executed. And, yep, i does throw error if i delete that line...

Well, i’ll play with spiout if i manage to get anywhere, but first tests show that i’ll have to use two mcu’s anyway. The reason is that readhitag takes up to one second or so, and i have to read keyboard, too, so this delay is not acceptable in my case. So i will have to use one micro for rfid read, and it will send data via uart into second micro.

But still it would be nice to be able to change HTRC settings...
I would use RDM6300 for RFID reading, which would be easier since it’s output is in uart format, but it has too short reading distance, only about 3cm max. HTRC reads up to 7-8cm.

Thanks for your help!
Back to top
View user's profile Visit poster's website
MWS

Bascom Member



Joined: 22 Aug 2009
Posts: 2262

blank.gif
PostPosted: Sat Jan 02, 2021 6:12 pm    Post subject: Reply with quote

protoncek wrote:
And, yep, i does throw error if i delete that line...

I does throw, or it does not?
Here it does not.

Also I found out why it does not give any reaction.
It's simply because, as well the .equs are all available, the (scrambled) assembler code is all hardwired and does not use the .equs.
The .equs, which are an ASM-equivalent to Const, did not make it into the code.

Maybe the reason is here:
Quote:
History = This library is based on a Philips C example and AN97070 from Philips. This code from Philips may not be distributed.
History = For this reason there is no public LIB file too.


What do you want to do, change the lbx?
Look for .OBJ E791, there's only one occurrence, in my lbx at line 142.

Modify it to read .OBJ E793, save the lbx, recompile and you should be set.
Back to top
View user's profile
MWS

Bascom Member



Joined: 22 Aug 2009
Posts: 2262

blank.gif
PostPosted: Sat Jan 02, 2021 6:32 pm    Post subject: Reply with quote

protoncek wrote:
The reason is that readhitag takes up to one second or so, and i have to read keyboard, too, so this delay is not acceptable in my case.

It would not be suitable in other cases too.
One second? Can't imagine that, show your code.

Did you use the readhitag-sample? It uses a delay of 500ms between reads and works with an interrupt. As far as I understand, it should allow you to do other things there.
Else, using another timer interrupt for polling the keyboard should do too, only don't waste too much time.
Such as small controller should be able to handle all these tasks and dance Swan Lake with the rest of its processing power.
Back to top
View user's profile
enniom

Bascom Member



Joined: 20 Oct 2009
Posts: 537

PostPosted: Sat Jan 02, 2021 7:52 pm    Post subject: Reply with quote

MWS wrote:
Look for .OBJ E791, there's only one occurrence, in my lbx at line 142.

Modify it to read .OBJ E793, save the lbx, recompile and you should be set.


Not many would have found this!!

E
Back to top
View user's profile
protoncek

Bascom Member



Joined: 16 May 2011
Posts: 52
Location: Slovenia

slovenia.gif
PostPosted: Sat Jan 02, 2021 8:41 pm    Post subject: Reply with quote

Quote:
I does throw, or it does not?
Here it does not.

Sorry... i confused things. An error showed when i deleted lbx, just to be sure that Bascom is using it at all. I did that because nothing happened when i changed the LBX. (i put it back, of course).

Quote:
What do you want to do, change the lbx?
Look for .OBJ E791, there's only one occurrence, in my lbx at line 142.

Modify it to read .OBJ E793, save the lbx, recompile and you should be set.

YES! It works! Thanks a lot! Like @enniom said: not many would have found this!! One part of my problem is fixed.

Quote:
One second? Can't imagine that, show your code.

here's the code. It's original demo, only added is my part for keyboard scanning. Readhitag slows down scanning from several hundred per second to 2-3 per second.
But, as you suggested, i can try with additional interrupts instead with constant scanning, but i kinda doubt it will help, since it seems that MCU is "stuck" at IF READHITAG.... command quite a while...

Code:
'--------------------------------------------------------------------------
'                    (c) 1995-2013  , MCS Electronics
' sample : readhitag.bas
' demonstrates usage of the READHITAG() function
'--------------------------------------------------------------------------

$regfile = "m8515.dat"                                                           ' specify chip
$crystal = 16000000                                                              ' used speed
$baud = 38400                                                                    'baud rate

'Config Lcd = 16 * 2
'Config Lcdpin = Pin , Db4 = Portc.4 , Db5 = Portc.5 , Db6 = Portc.6 , Db7 = Portc.7 , E = Portd.6 , Rs = Porta.2
'Cursor Off Noblink


'1=output, 0=input ----------- PORT C
'C.0 vr1
'C.1 vr2
'C.2 vr3
'C.3 vr4
'C.4 st1
'C.5 st2
'C.6 st3
'C.7
Config Portc = &B1111_0000
Portc = &B0000_0000

Vr1 Alias Pinc.0
Vr2 Alias Pinc.1
Vr3 Alias Pinc.2
Vr4 Alias Pinc.3
St1 Alias Portc.4
St2 Alias Portc.5
St3 Alias Portc.6

Set Portc.0
Set Portc.1
Set Portc.2
Set Portc.3

Cls
Lcd "HTC110 demo"
Wait 1
Cls
Config Hitag = 64 , Type = Htrc110 , Dout = Pind.2 , Din = Pind.3 , Clock = Pind.4 , Int = @int0
'                ^ use timer0 and select prescale value 64
'                     ^ we used htrc110 chip
'                                      ^-- dout of HTRC110 is connected to PIND.2 which will be set to input mode
'                                                     ^ DI N of HTRC100 is connected to PIND.3 which will be set to output mode
'                                                                    ^clock of HTRC110 is connected to PIND.4 which is set to output mode
'                                                                                     ^ interrupt
Dim Tags(5) As Byte                                                              'each tag has 5 byte serial

Dim J As Byte , Tipka As Byte                                                    ' a loop counter

Config Portb.0 = Output
Led Alias Portb.0


On Int0 Checkints                                                                ' PIND.2 is INT0
Config Int0 = Change                                                             'you must configure the pin to work in pin change intertupt mode
Enable Int0
Enable Interrupts                                                                ' Enable Global Interrupts

Do
   Locate 1 , 1
   If Readhitag(tags(1)) = 1 Then
      Set Led                                                                    'check if there is a new tag ID
      For J = 5 To 1 Step -1
          Print Str(tags(j));                                                    'print the 5 bytes
         'Lcd Hex(tags(j)) ;
         'Tags(j) = 0
      Next

   Else
      Reset Led                                                                  'there was nothing
      For J = 1 To 5                                                             'print the 5 bytes
         'Lcd "00" ;
      Next

   End If
   
   'reading keyboard
   Gosub Read_kbd
   Toggle Led
Loop



'this routine is called by the interrupt routine
Checkints:

   Call _checkhitag                                                              'you must call this label
 'you can do other things here but keep time to a minimum
Return


Read_kbd:
   Tipka = 100
  'St1 = 0
   St2 = 1
   St3 = 1
   Waitms 1
   If Vr1 = 0 Then Tipka = 1
   If Vr2 = 0 Then Tipka = 4
   If Vr3 = 0 Then Tipka = 7
   If Vr4 = 0 Then Tipka = 10

   St1 = 1
   St2 = 0
  'St3 = 1
   Waitms 1
   If Vr1 = 0 Then Tipka = 2
   If Vr2 = 0 Then Tipka = 5
   If Vr3 = 0 Then Tipka = 8
   If Vr4 = 0 Then Tipka = 0

  'St1 = 1
   St2 = 1
   St3 = 0
   Waitms 1
   If Vr1 = 0 Then Tipka = 3
   If Vr2 = 0 Then Tipka = 6
   If Vr3 = 0 Then Tipka = 9
   If Vr4 = 0 Then Tipka = 11

   St1 = 0
   St2 = 0
  'St3 = 0
  'St4 = 0
Return

 
Back to top
View user's profile Visit poster's website
MWS

Bascom Member



Joined: 22 Aug 2009
Posts: 2262

blank.gif
PostPosted: Sat Jan 02, 2021 10:00 pm    Post subject: Reply with quote

I guess Readhitag() times out after a while, this timeout may be the slowest rate.
You set up the interrupt extension, but you do not use it. As far I understand this is for letting other code execute, while Readhitag() tries to detect some card. On the other hand, if there's no card, then tis interrupt-stub will not work, as no interrupt occurs.

I'd go for a timer interrupt and I'd set up a state machine for the keyboard to eliminate the need for wait cycles, that's in the first state
Code:
St2 = 1
St3 = 1

is set, at second call of the timer ISR, next state is entered
Code:
If Vr1 = 0 Then Tipka = 1
If Vr2 = 0 Then Tipka = 4

a.s.o., the time between timer calls eliminates the need of waitms().
In the same timer ISR a flag can be set, for example every 250ms. This can be used to slow down the LCD update to reasonable rates, if Readhitag()'s rate goes faster than 2 to 3 per second.

LCD update must be done in the main loop, as it is slow and it does not matter whether the user gets feedback a few 100ms later.

Basically if no more timing sensible interfaces are added, then one controller is enough for the purpose.
Whatever you do, keep in mind:
- Keep ISRs short
- Avoid any waits
- Use state machines wherever possible

If you do not make use of the Readhitag()'s Interrupt extension, then remove it, as it wasts only processor cycles.
Back to top
View user's profile
protoncek

Bascom Member



Joined: 16 May 2011
Posts: 52
Location: Slovenia

slovenia.gif
PostPosted: Sun Jan 03, 2021 9:36 am    Post subject: Reply with quote

Thanks for the tips! I know that wait, goto...are kind of “forbidden” commands for real programmers (so i’ve been told). But I’m just a hobby programmer and still a lot to learn...
I’ll try with interrupts as you suggested. In my end application i won’t be using LCD at all, there will be only a tricolor led to show states, and MCU will have to scan for Rfid tag, keypress and uart messages (i’ll have two slave units to open two garage doors and one main unit which controls alarm). Since uart and rfid are already on interrupt only keyboard is left to be there. I guess that some experimenting (and learning) is at sight.
But, a big thing towards success is solved by running at max speed (16MHz)m thanks to you. Of course, i could add a quartz on HTRC, but if it’s not needed, it’s one element less...
Thanks again!
Back to top
View user's profile Visit poster's website
protoncek

Bascom Member



Joined: 16 May 2011
Posts: 52
Location: Slovenia

slovenia.gif
PostPosted: Sun Jan 03, 2021 10:44 am    Post subject: Reply with quote

MWS wrote:
If you do not make use of the Readhitag()'s Interrupt extension, then remove it, as it wasts only processor cycles.

I don't follow you here...
i disabled "Call _checkhitag" interrupt and in this case whole program hangs at "If Readhitag(tags(1))...".
So, this interrupt is mandatory. In fact, i just found out that this interrups itself is to blaim for time consuming: I changed demo program so that "readhitag" executes only if interrupt occurs but i saw that there's no difference. So, i fired up my oscilloscope and monitored HTRF lines. Voila! The problem is that Dout (portd.2) CONSTANTLY sends output - some random data, i guess, but enough that interrupt is constantly triggered and that is what "eats" all MCU time.
I guess i will have to switch to RDM6300 after all.. this chip at least sends UART only when card is present. I'll have to work on range, though...


Code:

Do
   Set Led2
   If Readhitag(tags(1)) = 1 Then
      Set Led                                                                    'check if there is a new tag ID
      For J = 5 To 1 Step -1
         Print Str(tags(j));                                                     'print the 5 bytes
      Next

   Else
      Reset Led                                                               'there was nothing
   End If

   Reset Led2
   Waitms 500
Loop



'this routine is called by the interrupt routine
Checkints:
   Call _checkhitag                                                              'you must call this label
   Set Rfid_flag
Return


I attached screenshot of LED2 flashing (see above program)which basically measures time, needed for IF routine to execute. LEFT side is when no card present, RIGHT side is card present. Note change in pulsewidth - it's quite narrower when card present, which suggests that when no card is present software tries to decode input signal, but gives up after a while.

I'll play around some more...
Back to top
View user's profile Visit poster's website
enniom

Bascom Member



Joined: 20 Oct 2009
Posts: 537

PostPosted: Sun Jan 03, 2021 1:35 pm    Post subject: Reply with quote

protoncek wrote:
The problem is that Dout (portd.2) CONSTANTLY sends output - some random data, i guess


This seems unusual. Maybe a weak pullup or pulldown could solve the problem?

E
Back to top
View user's profile
protoncek

Bascom Member



Joined: 16 May 2011
Posts: 52
Location: Slovenia

slovenia.gif
PostPosted: Sun Jan 03, 2021 3:38 pm    Post subject: Reply with quote

No, pull-ups (downs) are no help.
I did some "homework" though: it seems that after initialization this chip works in so-called "transparent mode", which means that all antenna data is constantly fed directly to Dout pin. It seems that this bascom demo is written this way.
Other way is (supposely) to drive sck pin low, but in that case you must manually trigger each read by sending read commands regularly. However, if i put sck to +5V manually data out stops and there's no way to make it work again unless i reset MCU.

So, it seems that in startup routine read_Tag is sent and never again. I tried to use SPIOUT but doesn't work. I configured SPI to same pins as hitag, but when i send spiout command whole thing hangs.

I think that my first intention is the easiest way to go: to use a separate MCU just for this purpose.
Back to top
View user's profile Visit poster's website
MWS

Bascom Member



Joined: 22 Aug 2009
Posts: 2262

blank.gif
PostPosted: Sun Jan 03, 2021 4:17 pm    Post subject: Reply with quote

protoncek wrote:
MWS wrote:
If you do not make use of the Readhitag()'s Interrupt extension, then remove it, as it wasts only processor cycles.

I don't follow you here...

I wrote it because I found in the help's sample code:
Quote:
'In case you want to use INT option

And 'option' tells me 'optional' = 'can be left out', however usage of the external interrupt seems to be a must.
Quote:
i just found out that this interrups itself is to blaim for time consuming:

Not exactly, the functionality seems to be desired exactly this way, note the call to _checkhitag within the ISR.
Quote:
but enough that interrupt is constantly triggered and that is what "eats" all MCU time.

Readhitag() tries 64 times to detect a card, this is the different high-time you can observe with and without card.
Each time Readhitag() does a check, it wasts up some time based on Timer0, which is used to measure pulse lengths.
Means the time of impulse sampling is wasted in any case.
Look also for _htc_Retries in the lbx, this is a SRam-Byte and repeatedly reset to its hardwired default of 64, number of retries.
It is not clear to me why DOUT (which has internal pullup) is used to trigger Int0, which then again calls _checkhitag.
Especially it is not clear because random output data from DOUT also will randomly trigger Int0, which reacts on pin change.
A series of 00001111 will trigger 1 to 3 interrupts, while a DOUT of 01010101 may trigger 7 to 9 times.
However, in case of whatever reason the interrupts appear periodically enough, the interrupt-stub may be suitable to hold your keyboard routine.
Maybe the htrc110 spits out only one transition on DOUT if no card is detected, a cheap logic analyzer would tell.
Quote:
I guess i will have to switch to RDM6300 after all.. this chip at least sends UART only when card is present.

Up to you.
I still think this chip can do the job, as requirements are rather low.
Back to top
View user's profile
protoncek

Bascom Member



Joined: 16 May 2011
Posts: 52
Location: Slovenia

slovenia.gif
PostPosted: Sun Jan 03, 2021 5:28 pm    Post subject: Reply with quote

MWS wrote:
'In case you want to use INT option
And 'option' tells me 'optional' = 'can be left out', however usage of the external interrupt seems to be a must.

Hm...i think that this is meant either PCINT (pin interrupt) or INT (normal interrupt). Mega8515 doesn't have pin interrupts anyway, so my only option is to use INT.

But, for testing i did try to move "Call _checkhitag" into main loop and disabled interrupts, but it doesn't work (it stucks somewhere...), so it seems that interrupts are needed for triggering someting. Interesting...


MWS wrote:
Up to you.
I still think this chip can do the job, as requirements are rather low.

Oh, it's not over yet:wink: I have time, because i do have working readers already, i would just like to update them with some more functionality, like a bit faster working, ditch LCD's (they tend to get nasty outside on sun after a while), more "decent" code... etc... It's winter here, so changing whole system will wait until warmer weather in any case.

I will definitely play some more with that. I like to play with these "small" MCU's. I don't do ARM's, since 1.) they use C, which i hate (don't ask me why...), 2.) they are way too complicated, 3.) they are way too powerfull for my needs....
Back to top
View user's profile Visit poster's website
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5921
Location: Holland

blank.gif
PostPosted: Mon Jan 04, 2021 9:16 pm    Post subject: Reply with quote

the equs are compiled. attached a version where * were used in the code so it will be compiled at compile time of the code.
this allows to change the .equ

the timer is used to measure the pulse width. so it has a load on the micro.
you could disable the timer interrupt and only enable it once in a while.

_________________
Mark
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-AVR 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