AnsweredHot!PIC18F2431 , who can help me to make it work

Page: 123 > Showing page 1 of 3
Author
gkuijpers@telkomsa.net
Starting Member
  • Total Posts : 63
  • Reward points : 0
  • Joined: 2015/09/16 10:03:22
  • Location: 0
  • Status: offline
2015/10/31 09:17:20 (permalink)
0

PIC18F2431 , who can help me to make it work

Who is able to help me.
I have a problem in getting the ADC to work with 4 sequential readings with a PIC18F2431. Whatever I have tried, I could only read  the 1 register reading, which was also loaded in all other 3 external registers.
According to the info at hand, the register gets automatically emptied after reading the ADRESH or ADRESL is transferred to another register.
Here are my settings and basic loop.
I am reading AN0, AN1,AN2  and AN3. 
ReadADC
                                bsf          ADCON0,GO       ; start the analogue to digital converter 
                                btfsc      GO_DONE,1       ; check whether A/D properly has read
                                goto        $-1
                                movf     ADRESH,w           ; get ADC result
                                movwf  ADC                       ; save result in speed control threshold
                                movwf  TEMP1
                                movf     ADRESH,w           ; get ADC result
                                movwf  TEMP3
                                movf     ADRESH,w           ; get ADC result
                                movwf  TEMP2
                                movf     ADRESH,w           ; get ADC result
                                movwf  TEMP4
                                clrf          STATUS
                                movf     TEMP2,w
                                bsf          ADCON0,GO      ; restart ADC
                                return
 
SetAN0
                                movlw  B'00010000'
                                movwf  ADCON1
                                movlw  B'00100001'
                                movwf  ADCON2
                                movlw  B'00000100'
                                movwf  ADCON3
                                movlw  B'00000000'
                                movwf  ADCHS
                                movlw  B'00001111'
                                movwf  ANSEL0                 ; ensure AN0,1,2 ADC input is analogue
                                movlw  B'00010101'        
                                movwf  ADCON0
                                bsf     ADCON0,GO           ; start ADC 
                                return
 
What did I do wrong?????
Bert
#1
DarioG
leaving this planet
  • Total Posts : 53071
  • Reward points : 0
  • Joined: 2006/02/25 08:58:22
  • Location: porcodioland
  • Status: offline
Re: PIC18F2431 , who can help me to make it work 2015/10/31 11:41:01 (permalink)
0
I am not sure about your ADC settings, but...
 
Unless this is a special case, usually PIC18 don't have a "FIFO" in ADC: so you have to perform a conversion, read the result, and change channel and start next conversion... and so on...

Dario Greggio
--
how does it feel, never having been loved? as life fades away, day after day, on this planet made of s h i t...

#2
DarioG
leaving this planet
  • Total Posts : 53071
  • Reward points : 0
  • Joined: 2006/02/25 08:58:22
  • Location: porcodioland
  • Status: offline
Re: PIC18F2431 , who can help me to make it work 2015/10/31 12:48:22 (permalink)
0
So, a FIFO *is* in there. nice to know wink

Dario Greggio
--
how does it feel, never having been loved? as life fades away, day after day, on this planet made of s h i t...

#3
gkuijpers@telkomsa.net
Starting Member
  • Total Posts : 63
  • Reward points : 0
  • Joined: 2015/09/16 10:03:22
  • Location: 0
  • Status: offline
Re: PIC18F2431 , who can help me to make it work 2015/10/31 13:18:25 (permalink)
+1 (1)
Thank you Diarog for relplying, But that is my problem. I have set the FIFOon 4th bit in the ADCON1 Register. I also have tried to do in a single conversion and then change the channel, but without success. Bert
#4
gkuijpers@telkomsa.net
Starting Member
  • Total Posts : 63
  • Reward points : 0
  • Joined: 2015/09/16 10:03:22
  • Location: 0
  • Status: offline
Re: PIC18F2431 , who can help me to make it work 2015/10/31 13:34:20 (permalink)
0
Hi Dario , thank you for the help. I don't understand what you mean with 'write output to LATx' My brushless motor runs absolute beautiful on a program I have compiled. (outputs RB0 - RB5) But my over current loop and my over heating loop, I am trying to build into PIC18F2431 system, is failing. Mainly because it reads the wrong information. I made it with a PIC12F675 as a separate entity and it works, but I don't want the 2 extra PIC's in the loop and try to do this thus with the FIFO and 4 sequential readings and it should theoretical work. I just make somewhere an error. Bert
#5
crosland
Super Member
  • Total Posts : 1094
  • Reward points : 0
  • Joined: 2005/05/10 10:55:05
  • Location: Bucks, UK
  • Status: offline
Re: PIC18F2431 , who can help me to make it work 2015/10/31 14:26:16 (permalink)
0
Have you #defined GO_DONE to ADCON0?
#6
gkuijpers@telkomsa.net
Starting Member
  • Total Posts : 63
  • Reward points : 0
  • Joined: 2015/09/16 10:03:22
  • Location: 0
  • Status: offline
Re: PIC18F2431 , who can help me to make it work 2015/10/31 22:51:34 (permalink)
0
Thank you Crosland, I think there is a misunderstanding. Everything is working perfectly, I am able to read the first register correctly in what the content should be, but the content of the second register is rubbish and the same is in the 3rd register. I have to read the fourth register and don't use it, but the reason is that I need to keep the buffers clear when reading the next time. It has to do with somewhere I have missed something. Thanks for your help, do you have any other suggestion? 
#7
DarioG
leaving this planet
  • Total Posts : 53071
  • Reward points : 0
  • Joined: 2006/02/25 08:58:22
  • Location: porcodioland
  • Status: offline
Re: PIC18F2431 , who can help me to make it work 2015/11/01 03:10:29 (permalink)
0
[not sure why the other replied disappeared, but ok... people are strange...]
 
I read the datasheet from your PIC, later, and indeed your code should work, at least for the "extract the 4 results" part. Now I am not sure about your other settings for sampling, channels to use etc: but, I would start with the "old-compatible" mode, and read one value at a time.

Dario Greggio
--
how does it feel, never having been loved? as life fades away, day after day, on this planet made of s h i t...

#8
gkuijpers@telkomsa.net
Starting Member
  • Total Posts : 63
  • Reward points : 0
  • Joined: 2015/09/16 10:03:22
  • Location: 0
  • Status: offline
Re: PIC18F2431 , who can help me to make it work 2015/11/01 03:51:59 (permalink)
+1 (1)
Thanks Dario, your info is much appreciated. The problem is, the PIC18F2431 reads all 4 pins at the same cycle but sequentially and put it into 4 buffers, which are read BACK, according what I understood, sequentially again, but one after the other by reading the ADRESH register. This happens in my view when it is placed in the w register. I then move it over to the temporary registers Temp1, Temp2, Temp3 and Temp4. Of which I ignore the contents of Temp4, because I only need the first reading from my speed potentio meter, the second reading from my  1 millOhm shunt resistor for the over current and the 4700 Ohm resistor for the over heating measurements.  Temp1 is absolute spot on, it regulates the speed of the motor beautiful.  However somewhere I miss something and have run out of what I could still try. Maybe you can give me some hints if you read it and interpreted in your way. I may have totally miss read the information. Thanks Bert
#9
gkuijpers@telkomsa.net
Starting Member
  • Total Posts : 63
  • Reward points : 0
  • Joined: 2015/09/16 10:03:22
  • Location: 0
  • Status: offline
Re: PIC18F2431 , who can help me to make it work 2015/11/01 04:59:01 (permalink)
0
Hi Dario,
Further to my reply to you on the previous thread. That is how I interpreted the pages 246, 247 and page 248 of the PIC18F2431 datasheet pdf file. Bert 
#10
gkuijpers@telkomsa.net
Starting Member
  • Total Posts : 63
  • Reward points : 0
  • Joined: 2015/09/16 10:03:22
  • Location: 0
  • Status: offline
Re: PIC18F2431 , who can help me to make it work 2015/11/01 07:30:56 (permalink)
0
Hi Crosland, You are not the only one, I am also on a boating forum and that also happens often to me. This PIC18F2431 problem is for my electric boat which I have build (5,5 mtr waterline) I need to solve this problem, because if a brushless motor stalls, due to weed or a rope in the propeller, the very low resistance of a brushless motor is so low that it will draw a few thousand ampere on a 36 Volt/4 Kwh battery system. Therefore I am grateful for any suggestion I am getting from you and other forum members.  Bert
#11
1and0
Access is Denied
  • Total Posts : 7134
  • Reward points : 0
  • Joined: 2007/05/06 12:03:20
  • Location: Harry's Gray Matter
  • Status: offline
Re: PIC18F2431 , who can help me to make it work 2015/11/01 09:28:48 (permalink)
0 (1)
gkuijpers@telkomsa.net
                                btfsc      GO_DONE,1       ; check whether A/D properly has read
                                goto        $-1

I think Crosland was referring to the above snippet, and the program address must be word-aligned; so try this:
        btfsc   ADCON0,DONE
        bra     $-2

 
#12
DarioG
leaving this planet
  • Total Posts : 53071
  • Reward points : 0
  • Joined: 2006/02/25 08:58:22
  • Location: porcodioland
  • Status: offline
Re: PIC18F2431 , who can help me to make it work 2015/11/01 12:12:49 (permalink)
0
Ok!
As I said, I would suggest you to avoid the FIFO and start with the "old style" convert/read mode.
 
PS: as for the LAT thing, it's just my standard signature - does not relate to your post! Smile

Dario Greggio
--
how does it feel, never having been loved? as life fades away, day after day, on this planet made of s h i t...

#13
gkuijpers@telkomsa.net
Starting Member
  • Total Posts : 63
  • Reward points : 0
  • Joined: 2015/09/16 10:03:22
  • Location: 0
  • Status: offline
Re: PIC18F2431 , who can help me to make it work 2015/11/01 13:31:13 (permalink)
0 (1)
Thank you Land0, Yes it makes a difference between your
btfsc   ADCON0, DONE
bra      $-2
 
and >>>>>>>>>>>>>>>>>>>>>>>>
 
btfsc  GO_DONE,1 
goto    $-1
 
and also >>>>>>>>>>>>>>>>>>>>>
 
btfsc   ADCON0, NOT_DONE
return
btfsc   GO_DONE,1
goto   $-1
 
However it is late already and everybody is already gone to bed. ( I am 75). All three solutions work for the first register (AN0 - buffer address 0 [00].  But I hear in the motor a different sounds and will tomorrow fully investigate which one is the best. 
 
Thank you so much for the tip. I can only test tomorrow what it means for the other 3 buffers, address 1[01], address 2 [02] and address 3 [03]
Bert
#14
gkuijpers@telkomsa.net
Starting Member
  • Total Posts : 63
  • Reward points : 0
  • Joined: 2015/09/16 10:03:22
  • Location: 0
  • Status: offline
Re: PIC18F2431 , who can help me to make it work 2015/11/01 13:55:10 (permalink)
+1 (1)
Viele Dank Mario, Yes, you probably are right that it may work. However I lose a lot of time  by reading 3 times in the loop and will do everything in my power to try to make it work with the FIFO solution/single read. A few microseconds could mean, my brushless motor is burned out at the middle of a lake or on the sea. It should be possible if Microchip allows to do that solution. Just that I am not experienced enough with the PIC18F2431,  that is what my problem is.  Thank you for your help. Sorry for not grasping your Latx, I see you are 27 years younger than me and probably have much more experience.  Don't stop trying to help me, thanks . Bert
#15
DarioG
leaving this planet
  • Total Posts : 53071
  • Reward points : 0
  • Joined: 2006/02/25 08:58:22
  • Location: porcodioland
  • Status: offline
Re: PIC18F2431 , who can help me to make it work 2015/11/01 14:12:26 (permalink)
0
Smile yvw.
Really some 10th of uSecs can cause problems to a motor?

Dario Greggio
--
how does it feel, never having been loved? as life fades away, day after day, on this planet made of s h i t...

#16
ric
Super Member
  • Total Posts : 22098
  • Reward points : 0
  • Joined: 2003/11/07 12:41:26
  • Location: Australia, Melbourne
  • Status: offline
Re: PIC18F2431 , who can help me to make it work 2015/11/01 14:21:20 (permalink)
+5 (4)
1and0
gkuijpers@telkomsa.net
                                btfsc      GO_DONE,1       ; check whether A/D properly has read
                                goto        $-1

I think Crosland was referring to the above snippet, and the program address must be word-aligned; so try this:
        btfsc   ADCON0,DONE
        bra     $-2

 

Arrgh.
Any programmer working for me who persisted with that old "$-1" syntax would have some serious explaining to do.
That is just asking for problems. Just use a damn label, they don't cost anything!

I also post at: PicForum
Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
NEW USERS: Posting images, links and code - workaround for restrictions.
To get a useful answer, always state which PIC you are using!
#17
1and0
Access is Denied
  • Total Posts : 7134
  • Reward points : 0
  • Joined: 2007/05/06 12:03:20
  • Location: Harry's Gray Matter
  • Status: offline
Re: PIC18F2431 , who can help me to make it work 2015/11/01 17:43:28 (permalink)
0
ric
Any programmer working for me who persisted with that old "$-1" syntax would have some serious explaining to do.
That is just asking for problems. Just use a damn label, they don't cost anything!

I'd rather use a macro
#define loop bra $-2

and avoid having to name and type a unique meaningful label that for all practical purposes used only once.
 
post edited by 1and0 - 2015/11/01 17:55:52
#18
ric
Super Member
  • Total Posts : 22098
  • Reward points : 0
  • Joined: 2003/11/07 12:41:26
  • Location: Australia, Melbourne
  • Status: offline
Re: PIC18F2431 , who can help me to make it work 2015/11/01 18:57:39 (permalink)
+5 (3)
... then you insert some debugging into the loop, and it all falls over.
A label lets you clearly see every possible entry point to your code.
I'd usually name it along the lines of what I'm waiting for, i.e. "loop_adcdone",
but if you're particularl uninventive, then "loop1", "loop2", etc. would do.
 
 

I also post at: PicForum
Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
NEW USERS: Posting images, links and code - workaround for restrictions.
To get a useful answer, always state which PIC you are using!
#19
1and0
Access is Denied
  • Total Posts : 7134
  • Reward points : 0
  • Joined: 2007/05/06 12:03:20
  • Location: Harry's Gray Matter
  • Status: offline
Re: PIC18F2431 , who can help me to make it work 2015/11/01 20:39:08 (permalink)
+4 (2)
Inserting anything after a BTFSx, even with a label, is going to make it falls over. *  I have programmed in assembly for decades and have never had any problems with such macros using the symbol $.  YMMV.
 
<edit>
* For example,
loop_adcdone:
        btfsc   ADCON0,DONE
        nop
        bra     loop_adcdone

post edited by 1and0 - 2015/11/01 20:56:43
#20
Page: 123 > Showing page 1 of 3
Jump to:
© 2017 APG vNext Commercial Version 4.5