| View previous topic :: View next topic   | 
	
	
	
		| Author | 
		Message | 
	
	
		
			SherpaDoug
 
 
  Joined: 07 Sep 2003 Posts: 1640 Location: Cape Cod Mass USA 
			
			 
			 
			
			
			
			
			
			
			
  
		  | 
		
			
				| Suspect errors in PIC12LF1501.h file - how to tell? | 
			 
			
				 Posted: Sat May 21, 2016 1:21 pm     | 
				     | 
			 
			
				
  | 
			 
			
				I am new to the PIC12LF1501 so I wrote this small test program to try out a few features.  I found the DAC setup section of PIC12LF1501.h was wrong so I got the correct values from the datasheet.  But I still have two problems:
 
 
1) Pin A4 is stuck high.  I suspect something wrong with APFCON but I don't know how to fix it.
 
 
2) The DAC behaves as if the internal pull-up was active as all the levels are squashed towards VCC.  Have I declared something wrong or is this another fault in the PIC12LF1501.h file?
 
 
Software serial and timer1 work fine so far.  My compiler version 5.058.
 
 
 	  | Code: | 	 		  <main.h>
 
#include <12LF1501.h>
 
#device ADC=10
 
#use delay(internal=16MHz)
 
#use FIXED_IO( A_outputs=PIN_A4,PIN_A2,PIN_A0)
 
#define TX   PIN_A0
 
#define RX   PIN_A1
 
#define Bias   PIN_A2
 
#define ProxPwr   PIN_A4
 
#define ProxE   PIN_A5
 
 
#use rs232(baud=38400,parity=N,xmit=TX,rcv=RX,bits=8,stream=PORT1,errors)
 
 
<main.c>
 
#include <main.h>
 
int8 i;
 
 
void main()
 
{
 
// setup_dac(DAC_OUTPUT | DAC_VSS_VDD);
 
   setup_dac(0x80|0x10|0x04); //DAC enable | DACOUT2 | VDD-VSS 
 
 
   while(TRUE)
 
   {
 
      output_high(ProxPwr);
 
      delay_ms(8);
 
      output_low(ProxPwr);  //This line is stuck high
 
      printf("Hello World\n\r");
 
      for(i=0; i< 32; i++)
 
         {
 
         dac_write(i);   //These values are all squashed against the VCC rail
 
         delay_ms(1);
 
         }
 
      delay_ms(15);
 
   }
 
 
} | 	 
  _________________ The search for better is endless.  Instead simply find very good and get the job done. | 
			 
		  | 
	
	
		  | 
	
	
		
			jeremiah
 
 
  Joined: 20 Jul 2010 Posts: 1401
  
			
			 
			 
			
			
			
			
			
			
			
  
		  | 
		
			
				 | 
			 
			
				 Posted: Sat May 21, 2016 4:10 pm     | 
				     | 
			 
			
				
  | 
			 
			
				The data sheet says:
 
 	  | Quote: | 	 		  
 
Note: The ANSELA bits default to the Analog
 
mode after Reset. To use any pins as
 
digital general purpose or peripheral
 
inputs, the corresponding ANSEL bits
 
must be initialized to ‘0’ by user software.
 
 | 	  
 
 
Do you know if the compiler is setting those to digital for you or do you need to manually configure the i/o as digital? | 
			 
		  | 
	
	
		  | 
	
	
		
			SherpaDoug
 
 
  Joined: 07 Sep 2003 Posts: 1640 Location: Cape Cod Mass USA 
			
			 
			 
			
			
			
			
			
			
			
  
		  | 
		
			
				 | 
			 
			
				 Posted: Sat May 21, 2016 4:28 pm     | 
				     | 
			 
			
				
  | 
			 
			
				 	  | jeremiah wrote: | 	 		  
 
Do you know if the compiler is setting those to digital for you or do you need to manually configure the i/o as digital? | 	  
 
 
It does not behave as if the pins were setup as Analog.  Pin A4 is pulled high hard and DAC output pin A2 is pulled high not-so-hard.  I would expect an Analog pin to be Hi-Z. _________________ The search for better is endless.  Instead simply find very good and get the job done. | 
			 
		  | 
	
	
		  | 
	
	
		
			SherpaDoug
 
 
  Joined: 07 Sep 2003 Posts: 1640 Location: Cape Cod Mass USA 
			
			 
			 
			
			
			
			
			
			
			
  
		  | 
		
			
				 | 
			 
			
				 Posted: Sat May 21, 2016 7:07 pm     | 
				     | 
			 
			
				
  | 
			 
			
				Explicitly adding these fuses to main.h got Pin A4 working but I don't know why.
 
 
The DAC is still way off.  Simply using port_a_pullups(0); doesn't help.
 
 
 	  | Code: | 	 		  #FUSES NOPUT                    //No Power Up Timer
 
#FUSES MCLR                     //Master Clear pin enabled
 
#FUSES NOPROTECT                //Code not protected from reading
 
#FUSES NOBROWNOUT               //No brownout reset
 
#FUSES NOCLKOUT                 //I/O function on OSC2
 
#FUSES NOWRT                    //Program memory not write protected
 
#FUSES STVREN                   //Stack full/underflow will cause reset
 
#FUSES BORV19                   //Brownout reset at 1.9V
 
#FUSES NOLPBOR                  //Low-Power Brownout reset is disabled
 
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
 
 | 	 
  _________________ The search for better is endless.  Instead simply find very good and get the job done. | 
			 
		  | 
	
	
		  | 
	
	
		
			PCM programmer
 
 
  Joined: 06 Sep 2003 Posts: 21708
  
			
			 
			 
			
			
			
			
			
			
			
  
		  | 
		
			
				 | 
			 
			
				 Posted: Sat May 21, 2016 8:13 pm     | 
				     | 
			 
			
				
  | 
			 
			
				 	  | Quote: | 	 		  | Explicitly adding these fuses to main.h got Pin A4 working  | 	  
 
The differences between the two sets of fuses (after compilation) are
 
shown below.  All I see is brownout and put.   It shouldn't have affected
 
pin A4.  It's possible that the data sheet for the 12(L)F1501 is incorrect.
 
 
Original code with no fuses:
 
 	  | Code: | 	 		     Word  1: 3FC4   INTRC_IO NOWDT PUT MCLR NOPROTECT BROWNOUT NOCLKOUT
 
   Word  2: 1FFF   NOWRT STVREN BORV19 NOLPBOR NOLVP | 	  
 
Revised code with fuses added:
 
 	  | Quote: | 	 		     Word  1: 39E4   INTRC_IO NOWDT NOPUT MCLR NOPROTECT NOBROWNOUT NOCLKOUT
 
   Word  2: 1FFF   NOWRT STVREN BORV19 NOLPBOR NOLVP | 	 
  | 
			 
		  | 
	
	
		  | 
	
	
		
			Ttelmah
 
 
  Joined: 11 Mar 2010 Posts: 19967
  
			
			 
			 
			
			
			
			
			
			
			
  
		  | 
		
			
				 | 
			 
			
				 Posted: Sun May 22, 2016 2:12 am     | 
				     | 
			 
			
				
  | 
			 
			
				On the DAC, all that is missing, is a define for the DACOUT2 output. There needs to be something like:
 
 
#define DAC_OUTPUT2    0x90
 
 
Then:
 
 
setup_dac(DAC_OUTPUT2 | DAC_VSS_VREF);
 
 
Will do exactly what you are currently doing. Puzzlingly, you are selecting the DAC to use Vref+ as it's +ve, not the supply rail, so obviously need to do the same here, if this is what you actually want to do.....
 
If in fact you have to select this, in order to use Vdd, then the chip data sheet is wrong.
 
 
The other problem is interesting. 
 
 
As PCM_programmer says, the only thing that changes in the code listing, is the PUT, and BROWNOUT fuses. Nothing else at all. There is no erratum for the chip on these (my immediate suspicion, is that possibly there is actually a chip fault perhaps regarding using '11' in the brownout selection - there have been other chips with this...).
 
 
The first thing I'd have done, is disable the pull-ups:
 
 
   port_a_pullups(FALSE);
 
 
Interestingly this does _not_ clear the WPUEN bit, which is required to use the individual enables. I had to manually control this:
 
 	  | Code: | 	 		  
 
//In the config:
 
#bit WPUEN=getenv("BIT:WPUEN")
 
 
//Then in the code:
 
    WPUEN=FALSE;
 
 | 	  
 
If you check the data sheet, though it says the pull-ups are disabled, if the pin is configured as an output, it does _not_ say they are disabled if the pins are configured for analog.
 
Nowhere does the code posted access the option register which would control the 'master' enable for the pull-ups. It only accesses this if you change the interrupt edge, or the timer0 settings. The data sheet says the default for the pull up enable, is 'off', but this differs from most other chips where they default to 'on'. 
 
 
I'd suspect that the WPUEN bit is actually defaulting to 'ON', in some configuration modes, possibly affected by the fuses you have found. So suggest you try just disabling this using the WPUEN bit (and turning the pullups off), and see if this works.
 
 
This is almost certainly a 'chip oddity', rather than anything wrong/missing in the device database or the include file. | 
			 
		  | 
	
	
		  | 
	
	
		
			SherpaDoug
 
 
  Joined: 07 Sep 2003 Posts: 1640 Location: Cape Cod Mass USA 
			
			 
			 
			
			
			
			
			
			
			
  
		  | 
		
			
				 | 
			 
			
				 Posted: Sun May 22, 2016 7:43 am     | 
				     | 
			 
			
				
  | 
			 
			
				This enables pull-ups
 
 	  | Code: | 	 		  ....................    port_a_pullups(0xff); 
 
00A5:  MOVLW  FF
 
00A6:  MOVLB  04
 
00A7:  MOVWF  WPUA
 
00A8:  MOVLB  01
 
00A9:  BCF    OPTION_REG.WPUEN | 	  
 
 
This disables pull-ups
 
 	  | Code: | 	 		  ....................    port_a_pullups(0x00); 
 
00A5:  MOVLB  04
 
00A6:  CLRF   WPUA | 	  
 
 
But even with this setup
 
 	  | Code: | 	 		  ....................    setup_dac(0x80|0x10|0x00); //DAC enable | DACOUT2 | VDD-VSS  
 
00A3:  MOVLW  90
 
00A4:  MOVWF  DACCON0
 
....................    port_a_pullups(0x00); 
 
00A5:  MOVLB  04
 
00A6:  CLRF   WPUA | 	  
 
The DAC output is compressed to near the positive rail.  Maybe the issue not pull-ups but something is wrong with my use of the DAC. _________________ The search for better is endless.  Instead simply find very good and get the job done. | 
			 
		  | 
	
	
		  | 
	
	
		
			temtronic
 
 
  Joined: 01 Jul 2010 Posts: 9589 Location: Greensville,Ontario 
			
			 
			 
			
			
			
			
			
			
			
  
		  | 
		
			
				 | 
			 
			
				 Posted: Sun May 22, 2016 8:17 am     | 
				     | 
			 
			
				
  | 
			 
			
				OK, I've never used that PIC but...
 
'compressed' and 'squashed' re interesting to me....
 
 
1) what is the load resistor for the DAC output. has to be a 'spec' somewhere in the datasheet. needs to be some I assume.
 
 
2) is the Vref for the DAC 'solid' ? that might affect response
 
 
3) update speed ? is it below the max that PIC DAC can accept?
 
 
just ideas.....
 
 
Jay | 
			 
		  | 
	
	
		  | 
	
	
		
			Ttelmah
 
 
  Joined: 11 Mar 2010 Posts: 19967
  
			
			 
			 
			
			
			
			
			
			
			
  
		  | 
		
			
				 | 
			 
			
				 Posted: Sun May 22, 2016 8:18 am     | 
				     | 
			 
			
				
  | 
			 
			
				In your previous post, you were selecting it to use the external Vref. As I said all that is missing in the CCS settings, is the option to enable DACOUT2.
 
 
I'd also suggest disabling the comparator. DACOUT2, is the comparator output, and this is far more likely to significantly affect the DAC output, than the pull-ups. It is also selected as the timer0 input by default. 
 
 
Note that disabling the pullups, writes '0' to the weak pullup enable register, but does not separately put all the pullups under software control, while enabling them does put them under software control. It was this I was commenting on. I'd prefer it to also set them to software control, if they are set to off. 
 
 
So:
 
 	  | Code: | 	 		  
 
    port_a_pullups(FALSE); 
 
    WPUEN=FALSE; //software mode
 
 | 	  
 
Does this stop the compression?.
 
 
The DAC resistors are nominally 5KR, while the pullups only pull typically 100uA. How much squash are you seeing?. This would allow us to estimate if this is likely from the weak pull-ups. | 
			 
		  | 
	
	
		  | 
	
	
		
			SherpaDoug
 
 
  Joined: 07 Sep 2003 Posts: 1640 Location: Cape Cod Mass USA 
			
			 
			 
			
			
			
			
			
			
			
  
		  | 
		
			
				 | 
			 
			
				 Posted: Sun May 22, 2016 9:47 am     | 
				     | 
			 
			
				
  | 
			 
			
				To temtronic:
 
 
1)  The current load is only a 10X scope probe.  Eventually it will be a 1Meg resistor.
 
2)  The Vref is now the VDD supply rail.  At these loads it should not move much.
 
3)  I am testing with 1 millisecond time steps and I clearly see the steps on my scope.
 
 
To Ttelmah:
 
 
WPUEN is not defined.  Is there a graceful way to set bits in the OPTION register?
 
 
By "squashed" I mean that what should be an even staircase looks more like a stepwise RC decay curve with the first 3 or 4 steps filling most of the curve and successive steps getting smaller and smaller.  I'll try to post a scope trace.
 
 
Thanks guys for the help and pardon my semi-ignorance.  Used to use CCS ver 2&3 long ago but have been using Arduinos for the past several years. _________________ The search for better is endless.  Instead simply find very good and get the job done. | 
			 
		  | 
	
	
		  | 
	
	
		
			SherpaDoug
 
 
  Joined: 07 Sep 2003 Posts: 1640 Location: Cape Cod Mass USA 
			
			 
			 
			
			
			
			
			
			
			
  
		  | 
		
			
				 | 
			 
			
				 Posted: Sun May 22, 2016 11:51 am     | 
				     | 
			 
			
				
  | 
			 
			
				 	  | Code: | 	 		  
 
   #BYTE OPTION_REG = 0x095         //OPTION Register
 
   #BIT WPUEN = 0x095.7            // Weak pull up !enable
 
    port_a_pullups(FALSE); 
 
    WPUEN=FALSE; //software mode
 
 | 	  Does not stop the compression.
 
 
 	  | Ttelmah wrote: | 	 		  
 
The DAC resistors are nominally 5KR, while the pullups only pull typically 100uA. How much squash are you seeing?. This would allow us to estimate if this is likely from the weak pull-ups. | 	  
 
I see the following voltages: 	  | Code: | 	 		  DAC #0 = 0.331V  dV = 0.331
 
DAC #1 = 0.722V  dV = 0.391
 
DAC #2 = 1.01V  dV = 0.288
 
DAC #3 = 1.24V  dV = 0.23
 
DAC #4 = 1.42V  dV = 0.18
 
DAC #5 = 1.57V  dV = 0.15
 
---------
 
DAC #31 = 2.98V | 	  
 
At DAC = 0 there are no resistors, just the FET switch resistance so I would expect it to be much closer to VSS than 0.331V.  I even Ohmed out the breadboard and without the PIC it has over 20Meg from that pin to anywhere.  I changed to another PIC12LF1501 and it performed the same. _________________ The search for better is endless.  Instead simply find very good and get the job done. | 
			 
		  | 
	
	
		  | 
	
	
		
			PCM programmer
 
 
  Joined: 06 Sep 2003 Posts: 21708
  
			
			 
			 
			
			
			
			
			
			
			
  
		  | 
		
			
				 | 
			 
			
				 Posted: Sun May 22, 2016 12:15 pm     | 
				     | 
			 
			
				
  | 
			 
			
				What board are you using to test 12LF1501 ?   Is it a purchased board
 
or a self-constructed 3M breadboard ?  If it's a purchased board, what
 
manufacturer and model number ? | 
			 
		  | 
	
	
		  | 
	
	
		
			SherpaDoug
 
 
  Joined: 07 Sep 2003 Posts: 1640 Location: Cape Cod Mass USA 
			
			 
			 
			
			
			
			
			
			
			
  
		  | 
		 | 
	
	
		  | 
	
	
		
			PCM programmer
 
 
  Joined: 06 Sep 2003 Posts: 21708
  
			
			 
			 
			
			
			
			
			
			
			
  
		  | 
		 | 
	
	
		  | 
	
	
		
			SherpaDoug
 
 
  Joined: 07 Sep 2003 Posts: 1640 Location: Cape Cod Mass USA 
			
			 
			 
			
			
			
			
			
			
			
  
		  | 
		
			
				 | 
			 
			
				 Posted: Sun May 22, 2016 12:52 pm     | 
				     | 
			 
			
				
  | 
			 
			
				 	  | PCM programmer wrote: | 	 		  If I was doing this, I'd probably bend out the RA2 pin on the DIP package
 
so it's hanging in the air.  Then put a scobe probe on it.  Just to be sure. | 	  
 
 
Easy enough to do ... but it didn't help. _________________ The search for better is endless.  Instead simply find very good and get the job done. | 
			 
		  | 
	
	
		  | 
	
	
		 |