E/X-Mag Microcontroller Programming (Atmel AT90S2313)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • LorneCash
    Got XMOD? www.NiedTech.com
    • Aug 2005
    • 365

    #16
    Still having ACE problems

    Miscue,

    Thanks for the timer help, and I like your bucket analogy that's a good way to explain it.
    can you help me a bit more with the ACE?
    I had tried this a few days ago but it didn't seem to work:

    sbis PINB, ACE ; See if ACE is ready (ACE=6)
    rjmp ACE_Ready ; If ace is ready do the code

    I noticed at the bottom of the timer code you had this exact same thing but you jumped to resetACE. How exactly does that work do i have to continuously be resetting the line to a low and a high means that it saw something since the last time i reset it?

    I figured there must be a little more to it then just what I had because if it was just a matter of sensing a ball or not sensing a ball how could the difference be between ACE-1 and ACE-2. Could you please elaborate on that too? thanks.
    Last edited by LorneCash; 10-22-2005, 02:05 AM.

    Comment

    • Miscue
      Super Moderator

      • Oct 2000
      • 7105

      #17
      Originally posted by LorneCash
      Miscue,

      Thanks for the timer help, and I like your bucket analogy that's a good way to explain it.
      can you help me a bit more with the ACE?
      I had tried this a few days ago but it didn't seem to work:

      sbis PINB, ACE ; See if ACE is ready (ACE=6)
      rjmp ACE_Ready ; If ace is ready do the code

      I noticed at the bottom of the timer code you had this exact same thing but you jumped to resetACE. How exactly does that work do i have to continuously be resetting the line to a low and a high means that it saw something since the last time i reset it?

      I figured there must be a little more to it then just what I had because if it was just a matter of sensing a ball or not sensing a ball how could the difference be between ACE-1 and ACE-2. Could you please elaborate on that too? thanks.
      "ACE 1" just needed one successful read from the ACE. "ACE 2" needed like... X number of successful reads. So that ResetAce2 thing was... to reset the number of successful reads that it counted. Does it make any difference? Not that I can tell... "ACE 1" seems to be sufficient and "ACE 2" does no harm. I put two modes in there just in case...

      I don't know what's wrong with your ACE.
      Did you set the port resistors correctly?

      ldi r18, 0b00011100 ; Register Select = PB4, Data In = PB3, Clock = PB2
      out DDRB, r18 ; Set LED pins to output - all else input

      Comment

      • Miscue
        Super Moderator

        • Oct 2000
        • 7105

        #18
        Oh yeah... PB5 is for the tourny lock jumper.

        Comment

        • LorneCash
          Got XMOD? www.NiedTech.com
          • Aug 2005
          • 365

          #19
          OK here's what I have and I have no idea why it's not working:

          ...

          ldi R_temp,0b11111111
          out PORTB,R_temp

          ldi R_temp,0b00011100 ; Set Data Direction Register(Port B)
          out DDRB,R_temp

          ...

          ACE_Ready:
          ldi ZH,high(2*MESSAGE2) ; Change Message displayed (part1)
          ldi ZL,low(2*MESSAGE2) ; Change Message displayed (part2)
          rcall loadbyte ; Load Message to screen
          sbi PORTD,DS1_CE
          rjmp Loop1_1

          ...

          Loop1_1:
          sbis PINB, ACE ; See if ACE is ready
          rjmp ACE_Ready ; If ace is ready do the code

          sbis PIND, BTN_1 ; See if Top Button is pushed again
          rjmp Button1_2 ; If Top Button is pushed jump to SUB
          sbis PIND, TRIGGER ; If Trigger is pulled exit Button1 Loop
          ret
          rjmp Loop1_1 ; Continue to display Button1 (Loop)


          If I switch the line to say "sbis PORTD, 5" it works fine when i push the bottom button so i don't think its a flaw in the logic just in how i access the ACE. All i'm trying to do is make it say READY on the Display when i have the ACE covered with my finger. I tried loading other software and the ACE works fine with that. I'm really stuck here.

          Comment

          • Miscue
            Super Moderator

            • Oct 2000
            • 7105

            #20
            I think your logic is backwards.

            Try cbis PINB, ACE ; See if ACE is ready
            instead of sbis PINB, ACE ; See if ACE is ready

            ACE = 6 right?

            Comment

            • LorneCash
              Got XMOD? www.NiedTech.com
              • Aug 2005
              • 365

              #21
              Originally posted by Miscue
              I think your logic is backwards.

              Try cbis PINB, ACE ; See if ACE is ready
              instead of sbis PINB, ACE ; See if ACE is ready

              ACE = 6 right?

              There is no instruction cbis do you mean cbi or sbic? I tried sbic... do i have to clear it or set it first to "prime" it or something? Yea, ACE=6. Just to remind you in your post #13 you used sbis to jump to resetACE... What's resetACE all doing, you said before you used some type of counter for ACE 2, but i don't have any idea what would need to be reset unless it's just the counter reset.

              Comment

              • Miscue
                Super Moderator

                • Oct 2000
                • 7105

                #22
                Originally posted by LorneCash
                There is no instruction cbis do you mean cbi or sbic? I tried sbic... do i have to clear it or set it first to "prime" it or something? Yea, ACE=6. Just to remind you in your post #13 you used sbis to jump to resetACE... What's resetACE all doing, you said before you used some type of counter for ACE 2, but i don't have any idea what would need to be reset unless it's just the counter reset.
                There is no priming. I told you the wrong instruction... tried to do it from memory and mixed up the instructions. Whatever is the opposite of sbis... probably sbic.

                All that my ACE 2 mode does is look for X number of successful reads from the ACE - the theory was that it might be a more reliable way of reading from the ACE. Turned out to be unnecessary as far as I could tell.

                Here is a silly question: Is your ACE plugged in to the board? I'd check your physical connections.

                Comment

                • LorneCash
                  Got XMOD? www.NiedTech.com
                  • Aug 2005
                  • 365

                  #23
                  Originally posted by Miscue
                  There is no priming. I told you the wrong instruction... tried to do it from memory and mixed up the instructions. Whatever is the opposite of sbis... probably sbic.

                  All that my ACE 2 mode does is look for X number of successful reads from the ACE - the theory was that it might be a more reliable way of reading from the ACE. Turned out to be unnecessary as far as I could tell.

                  Here is a silly question: Is your ACE plugged in to the board? I'd check your physical connections.
                  It works fine with 3.2 and 4.01

                  Comment

                  • Miscue
                    Super Moderator

                    • Oct 2000
                    • 7105

                    #24
                    I don't have any more suggestions for you other than... have fun debugging. You'll probably slap yourself when you discover what the problem is.

                    Comment

                    • LorneCash
                      Got XMOD? www.NiedTech.com
                      • Aug 2005
                      • 365

                      #25
                      I got it, but i'm not sure i understand it completely... From what i got I had the pullup resistor for that bit on PORTB set wrong. Here's what i have now. Can you please check all 4 of the bytes i'm loading to confirm they're correct, and if you don't mind explain a bit about that.

                      ldi R_temp,0b10111111 ; Set Pullup Resistors(Port B)
                      out PORTB,R_temp ; Load them

                      ldi R_temp,0b00011100 ; Set Data Direction Register(Port B)
                      out DDRB,R_temp ; Load It

                      ...

                      ldi R_temp,0b10000000 ; Set Pullup Resistors(Port D)
                      out PORTD,R_temp ; Lead them

                      ldi R_temp,0b01001000 ; Set Data Direction Register(Port D)
                      out DDRD,R_temp ; Load it
                      Last edited by LorneCash; 10-25-2005, 12:19 AM.

                      Comment

                      • Miscue
                        Super Moderator

                        • Oct 2000
                        • 7105

                        #26
                        Originally posted by Miscue

                        I don't know what's wrong with your ACE.
                        Did you set the port resistors correctly?

                        Comment

                        • LorneCash
                          Got XMOD? www.NiedTech.com
                          • Aug 2005
                          • 365

                          #27
                          Sorry for the runnaround I didn't understand what those 2 lines were doing... I understood the DDRx is setting the Direction, 0 is input and 1 is output, and it's not too hard to figure out if the device is input or output, but the resistors thing i don't get.

                          In General, how do you know what the resistor should be set to? Even though I seem to have it set correctly now I would still like to understand why... comes with being an engineer... lol.

                          Comment

                          • bit-wizard
                            Registered User
                            • May 2005
                            • 205

                            #28
                            The PORTx reg is a multipurpose register. When the DDRx reg has a '1' in a given port pin location, the port is an output, and the value placed in the corresponding PORTx bit is output on the equivalent micro pin. When the DDRx reg has a '0' in the given port pin location, the port pin is set to an input, and the value placed in the PORTx reg bit determines whether the pullup is active '1' or not '0'. If it is active, then a 20 to 100K resister internally connects the pin to VCC. This "pulls" the input up to the supply when nothing external pulls it down. So if the pin was not connected to anything externally, it would be pulled to 5V and would be prevented from being a floating input, which is a bad thing in terms of power consumption. Another reason to use pullups is if the external device that is connected to the pin is an open collector or open drain output.

                            So it really boils down to what the external circuitry that is attached consists of as to whether or not you want the pullups on.

                            I'm purely speculating since I haven't seen the schematic, but is is possible that the external device connected to the input that you had configured incorrectly as a pullup ('1') may have had an associated pulldown (external to the micro). The 2 resistors (pullup and pulldown) would look like a resistive divider on to the input pin, which could keep it from changing state depending on the relative values of the resistors.

                            bit-wizard


                            Originally posted by LorneCash
                            Sorry for the runnaround I didn't understand what those 2 lines were doing... I understood the DDRx is setting the Direction, 0 is input and 1 is output, and it's not too hard to figure out if the device is input or output, but the resistors thing i don't get.

                            In General, how do you know what the resistor should be set to? Even though I seem to have it set correctly now I would still like to understand why... comes with being an engineer... lol.

                            Comment

                            • LorneCash
                              Got XMOD? www.NiedTech.com
                              • Aug 2005
                              • 365

                              #29
                              Timers again

                              OK midterms are over time to get back into this...

                              I have been looking at the timer stuff again and was reading in the AT90S2313 User Guide about Timer/Counters. Because of the nature of the timers needed for this project (30ms) I thought it would be easier to just execute a loop for a certain number of cycles based on the frequency of the chip. If i remember correctly the chip is a 4MHz chip so 4 instructions should equal 1ms.

                              Is this the best way to go about this or should i try to use the Counters?

                              Comment

                              • bit-wizard
                                Registered User
                                • May 2005
                                • 205

                                #30
                                Definitely use the hardware timers. Cycle counting is possible, but accuracy depends on several factors. First, most AVR instructions are single cycle, but NOT ALL instructions. Jumps, for instance, can take more than 1 cycle. Second, if you are using interrupts, they would throw off your cycle-count based timing because they can occur unpredictably.

                                Configuring the timers can be a bit of a pain initially, but it is well worth it in terms of the accuracy and flexibility that it allows. They make it much easier to change your code and functionality without having to count cycles by hand to make sure that you have just blown your timing by adding a few more instructions. In my experience, the overall project will be made much simpler in the long run if you use the hardware timers.


                                bit-wizard

                                Comment

                                Working...