Author Topic: tritiled - Change clock frequency on PIC12LF1571  (Read 634 times)

0 Members and 1 Guest are viewing this topic.

Offline joeyjoejoeTopic starter

  • Frequent Contributor
  • **
  • Posts: 267
  • Country: ca
tritiled - Change clock frequency on PIC12LF1571
« on: November 09, 2023, 10:38:49 pm »
Not a PIC guy but trying to get this sorted.

https://ww1.microchip.com/downloads/en/devicedoc/40001723d.pdf

I'm playing with a Tritiled ( https://github.com/tedyapo/tritiled ) and I'm getting flickering in the bottom half of the brightness levels.

I'm fumbling in the dark here, but I think I want to increase the clock speed from the 31kHz (lowest for power no doubt) to something a bit higher which will hopefully let me drive it faster?

I'm trying to put this in the first line of setup()

OSCCON = 0b00100000;

That should set it to 62.5kHz?

This is in addition to the code ( https://github.com/tedyapo/tritiled/blob/master/software/tritiled30/src/tritiled_v30_selectable_runtime.c ) having
// CONFIG1
#pragma config FOSC = INTOSC    // (INTOSC oscillator; I/O function on CLKIN pin)
#pragma config WDTE = ON        // Watchdog Timer Enable (WDT enabled)
#pragma config PWRTE = OFF      // Power-up Timer Enable (PWRT disabled)
#pragma config MCLRE = OFF      // MCLR Pin Function Select (MCLR/VPP pin function is digital input)
#pragma config CP = OFF         // Flash Program Memory Code Protection (Program memory code protection is disabled)
#pragma config BOREN = OFF      // Brown-out Reset Enable (Brown-out Reset disabled)
#pragma config CLKOUTEN = OFF   // Clock Out Enable (CLKOUT function is disabled. I/O or oscillator function on the CLKOUT pin)

// CONFIG2
#pragma config WRT = HALF       // Flash Memory Self-Write Protection (000h to 1FFh write protected, 200h to 3FFh may be modified by EECON control)
#pragma config PLLEN = OFF      // PLL Enable (4x PLL disabled)
#pragma config STVREN = ON      // Stack Overflow/Underflow Reset Enable (Stack Overflow or Underflow will cause a Reset)
#pragma config BORV = LO        // Brown-out Reset Voltage Selection (Brown-out Reset Voltage (Vbor), low trip point selected.)
#pragma config LPBOREN = OFF    // Low Power Brown-out Reset enable bit (LPBOR is disabled)
#pragma config LVP = OFF        // Low-Voltage Programming Enable (High-voltage on MCLR/VPP must be used for programming)



Can anyone let me know if I'm on the right track?
 

Offline SuzyC

  • Frequent Contributor
  • **
  • Posts: 792
Re: tritiled - Change clock frequency on PIC12LF1571
« Reply #1 on: November 09, 2023, 10:50:26 pm »
//You must periodically reset WDT in main() or things will flicker.   

CLRWDT();   //must be somewhere in main() loop

/*When the SCSx bits of the OSCCON register = 1x,
the system clock source is chosen by the internal
oscillator frequency selected by the IRCF<3:0> bits
of the OSCCON register.*/
//use
OSCCONbits.IRCF=nn;  //selects INTOSC divider ratio
// for example
nn=14; // sets INTOSC to 8mHz

//Other OSCCON freqs:


IRCF<3:0>: Internal Oscillator Frequency Select bits
1111 = 16 MHz HF
1110 = 8 MHz or 32 MHz HF (see Section 5.2.2.1 “HFINTOSC”)
1101 = 4 MHz HF
1100 = 2 MHz HF
1011 = 1 MHz HF
1010 = 500 kHz HF(1)
1001 = 250 kHz HF(1)
1000 = 125 kHz HF(1)
0111 = 500 kHz MF (default upon Reset)
0110 = 250 kHz MF
0101 = 125 kHz MF
0100 = 62.5 kHz MF
0011 = 31.25 kHz HF(1)
0010 = 31.25 kHz MF
000x = 31 kHz LF
« Last Edit: November 09, 2023, 11:12:01 pm by SuzyC »
 

Offline joeyjoejoeTopic starter

  • Frequent Contributor
  • **
  • Posts: 267
  • Country: ca
Re: tritiled - Change clock frequency on PIC12LF1571
« Reply #2 on: November 09, 2023, 11:03:30 pm »
Ok thanks. So, I did that, and presumably the clock changed. Flickering is still present.

I think WDT is handled.
Code: [Select]
  // exit run-time selection mode
  nPOR = 1;                   // exit startup mode
  WDTCONbits.WDTPS = 0b10010; // 256s WDT timeout to wake and refresh RAM   
  start_pwm(mode_idx);
  SLEEP();                    // PWMs run in sleep, pulsing LED
  RESET();       

Does the PWM need some other options to increase the resolution? The prescaler is already at 0.
 

Offline SuzyC

  • Frequent Contributor
  • **
  • Posts: 792
Re: tritiled - Change clock frequency on PIC12LF1571
« Reply #3 on: November 09, 2023, 11:13:18 pm »
//I don't see

CLRWDT(); //in your code


//PWM resolution is quite another story and requires setting a few other things, for example below:

void PWM1SETUP()
{
  P1SEL=1;             //if P1SEL=1 PWM1out=RA5, else P1SEL=0,RA1=PWM1 (APFCOM)
  PWM1CLKCONbits.CS=1; //0=FOSC 1=HFINTOSC PWM1 clk
  PWM1CLKCONbits.PS=0; //0=No Prescale, 1= 1:2  2=1:4 ... 7=128:1
  PWM1CONbits.POL=0;   //Output high at start of PWM cycle
  PWM1CONbits.MODE=0;  //Independent Mode
  PWM1CONbits.OUT=0;
  PWM1CONbits.EN=1;

  PWM1CON = 0b11000000;

 
  PWM1LDCONbits.LDT=0; //Continuous reload PWM period (standard PWM )
  PWM1OFCONbits.OFM=0; //No Offset(delay) of duty cycle
  PWM1LDCONbits.LDA=1; //Load DCyc values after PWM cycle ends, standard PWM
  PWM1PH=0;            //No phase offset of PWM cycle start
  PWM1DC=0;            //Duty cyc PWM1DCL PWM1DCH regs both updated at once
  PWM1PR=1024;          //Number of PWM OSC cycles = PWM Period
  PWM1OE=1;   
  if(P1SEL==1)
   {  TRISA5=0;          //PWM1out on RA5 pin2 when P1SEL=0, else RA1=PWM1out
   }                           // else TRISA1=0;       //if P1SEL=1 RA5=PWM1out
  DCyc=0;               //DCyc is a 16-bit unsigned var that sets PWM duty cycle somewhere in your code.
}
« Last Edit: November 09, 2023, 11:34:07 pm by SuzyC »
 

Offline joeyjoejoeTopic starter

  • Frequent Contributor
  • **
  • Posts: 267
  • Country: ca
Re: tritiled - Change clock frequency on PIC12LF1571
« Reply #4 on: November 09, 2023, 11:16:43 pm »
It looks like it's expected that after 256s, WDT will trigger and is handled by the main() function?
 

Offline SuzyC

  • Frequent Contributor
  • **
  • Posts: 792
Re: tritiled - Change clock frequency on PIC12LF1571
« Reply #5 on: November 09, 2023, 11:25:28 pm »
When WDT is triggered, your device is reset, this is a boot, your program is completely reset.
So, don't trigger it unless you want WDT to somehow briefly light a LED (this is crude, not a very usable/practical way to do anything)
 

Offline joeyjoejoeTopic starter

  • Frequent Contributor
  • **
  • Posts: 267
  • Country: ca
Re: tritiled - Change clock frequency on PIC12LF1571
« Reply #6 on: November 09, 2023, 11:26:17 pm »
I'm not the original author of the code, and it works. After the initial sequence, the startup section doesn't occur again.
 

Offline SuzyC

  • Frequent Contributor
  • **
  • Posts: 792
Re: tritiled - Change clock frequency on PIC12LF1571
« Reply #7 on: November 09, 2023, 11:29:41 pm »
So now write some code to do something practical you want done!
 

Offline joeyjoejoeTopic starter

  • Frequent Contributor
  • **
  • Posts: 267
  • Country: ca
Re: tritiled - Change clock frequency on PIC12LF1571
« Reply #8 on: November 10, 2023, 12:34:44 am »
Couldn't figure it out. I adjusted PWM2 PHASE to 2 and that seems to cause it to dim, and changed some of the lookups in modes.h
 

Offline SuzyC

  • Frequent Contributor
  • **
  • Posts: 792
Re: tritiled - Change clock frequency on PIC12LF1571
« Reply #9 on: November 10, 2023, 12:47:11 am »
You need to not expect anyone to know what you do not reveal codewise. You can change PWm2 phase to whatever you want but it seems you are talking to yourself about Alaska while all I know about is main() street.
 

Offline joeyjoejoeTopic starter

  • Frequent Contributor
  • **
  • Posts: 267
  • Country: ca
Re: tritiled - Change clock frequency on PIC12LF1571
« Reply #10 on: November 10, 2023, 12:59:06 am »
The entire code was in my first post. I'm sorry you missed that.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf