|
|
View previous topic :: View next topic |
Author |
Message |
camleot23
Joined: 16 Aug 2019 Posts: 52
|
[SOLVED]dsPIC33EP Internal Oscillator |
Posted: Mon Aug 19, 2019 5:33 am |
|
|
Hello All,
I want to use internal oscillator for my dsPIC33EP64MC206. I tried this
Code: |
#FUSES NOWDT //No Watch Dog Timer
#FUSES CKSFSM //Clock Switching is enabled, fail Safe clock monitor is enabled
#FUSES NOJTAG //JTAG disabled
#use delay(internal=7.37MHz)
|
I don't have any crystal to use.(My dspic is embedded to a pcb).I know this is wrong because when I change the 7.37 for example to 1MHz , my led is blinking so fastly. It shouldn't happen. I try to read datasheet but I just see assembler codes or set this register to something else. Also, I try project wizard and it gives me just that line that I shared above. I set it to 7.37 because in the datasheet it says the internal oscillator max. capacity with no PLL is this value.
I'm looking forward to your responses. I'm stuck and I need to move on. And also if I want to use internal oscillator with PLL do I have to use set_oscillator(....) funciton?
I use mplab ide with ccs c compiler.
Last edited by camleot23 on Wed Aug 21, 2019 7:16 am; edited 2 times in total |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19620
|
|
Posted: Mon Aug 19, 2019 9:51 am |
|
|
No, just tell the #use delay, the rate you want to use. However it needs
to be a rate that is supported by the PLL.
So
#use delay(internal=14.74MHz)
will merrily work, but:
#use delay(internal=10MHz)
won't.
The reason is that the available divider/PLL options can't get even 'close'
to 10MHz.
However it'll happily accept anything it can get within a couple of percent
of, and will simply report to you the actual frequency being 'nominally'
generated.
This is assuming you have a reasonably modern compiler. The automatic
setup of the PLL like this has only been available for perhaps the last
fifty compiler versions... |
|
|
camleot23
Joined: 16 Aug 2019 Posts: 52
|
|
Posted: Mon Aug 19, 2019 11:22 am |
|
|
Thank you.
I mentioned set_oscillator() because I read your or pcm programmer's response for someone who asks a question about something like this. So, if you say this #use delay(internal=7.37MHz) is enough and the multipliers of this for PLL.
My MPLAB ide CCS C compiler version is 3.10. Is it enough for this set up? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19620
|
|
Posted: Mon Aug 19, 2019 12:24 pm |
|
|
That sounds like the MPLAB version, not the CCS compiler version.
I don't think CCS 3.10, would support the dsPIC33EP64MC206.
The CCS compiler needs to be in the mid V5 versions to support
automatic setup like this. On V3 compilers I think you would have to
manually configure the PLL yourself. Old posts here on how to do this. |
|
|
camleot23
Joined: 16 Aug 2019 Posts: 52
|
|
Posted: Tue Aug 20, 2019 12:04 am |
|
|
I see. I will try that, thanks a lot. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19620
|
|
Posted: Tue Aug 20, 2019 12:58 am |
|
|
Just checked, and you must have something a lot later than 3.10.
CCS 3.10, launched in 2004. The DsPIC33EP64MC206, didn't launch till
several years later. It is listed in 4.141, but not in 4.118. So must have been added between 2011, and 2012. These early compilers wouldn't do the
clock control properly, but by perhaps 2014, we are up to versions that
should do this. |
|
|
camleot23
Joined: 16 Aug 2019 Posts: 52
|
|
Posted: Tue Aug 20, 2019 1:31 am |
|
|
Now, I checked my version from another place mplab>options>embedded>build tools, in here it says (v5.016). But, in plugins section it says compiler version is 3.10. I don't know which one is right one. But I suppose v5.016 is right one because, I can see header files of that pic and I can compile it and it can toggle led. Here is my code:
Code: |
#include <./33EP64MC206.h>
#fuses NOWDT,CKSFSM,NODEBUG,NOPR,FRC
#device ICSP=1
#use delay(internal=7370000)
#use i2c(master,I2C1,STREAM=lcd_kanal)
#include <./i2C_Flex_LCD_with_BIGNUMBERS.h>
int main()
{
setup_timer1(TMR_DISABLED); // T1 zamanlay?c?s? devre d???
setup_timer2(TMR_DISABLED); // T2 zamanlay?c?s? devre d???
setup_adc_ports(NO_ANALOGS); // ANALOG giri? yok
setup_adc(ADC_OFF); // ADC birimi devre d???*/
lcd_init();
while(1)
{
lcd_gotoxy(1,1);
delay_ms(100);
lcd_putc("deneme");
delay_ms(1000);
output_toggle(pin_b5);
}
} |
|
|
|
camleot23
Joined: 16 Aug 2019 Posts: 52
|
|
Posted: Tue Aug 20, 2019 5:31 am |
|
|
still the lcd is empty:/Also, I enabled osc out pin, when I measured that pin with oscilloscope, it gives me 3.68Mhz , it means half of the 7.37Mhz which is inside of my delay setup.Additionally when I change 7.37 to smaller ones that osc output freqeuncy doesn't change, but when I increase it to higher frequencies like 36Mhz- 18 Mhz; again osc out gives me half of them(18Mhz,9Mhz). I hope this results give you a point. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9297 Location: Greensville,Ontario
|
|
Posted: Tue Aug 20, 2019 6:43 am |
|
|
Since it appears the PIC is running..though there may be a setup issue..
the '1Hz LED' program would be a help to confirm the PIC is running properly
Also please post a link or the actual LCD driver.
Jay |
|
|
camleot23
Joined: 16 Aug 2019 Posts: 52
|
|
Posted: Tue Aug 20, 2019 6:55 am |
|
|
I already do it that 1 hz lcd technic, it seems it is working properly
Here my lcd library, it has big numbers.
2x16 hd44780
Code: | -----------------------------------------------------------------------------
// Title: i2c_Flex_LCD
// Description: Driver for common LCD with 1/2/3 or 4 rows by 1...20 columns
// using PCF8574T interface board with I2C protocol.
// Date: Nov-2013
// Ver.Rev.: 1.1
// Author: Hugo Silva ([email protected]) #Based on the routines of
// "20X4_LCD_I2C_DRIVER.h" from Pumrin S. and "lcd4_i2c.c" from XP8100
//-----------------------------------------------------------------------------
//
// lcd_init() Must be called before any other function.
//
//
//
//
// lcd_putc(c) Will display c on the next position of the LCD.
//
// \f Clear LCD dispay
// \n Set write position on next lcd line
// \b LCD backspace
// lcd_gotoxy(x,y) Set write position on LCD (upper left is 1,1)
//
// lcd_backlight_led(ON)/lcd_backlight_led(OFF) = Turn ON/OFF LCD Backlight LED
//
//-----------------------------------------------------------------------------
// LCD pins D0-D3 are not used.
//-----------------------------------------------------------------------------
//
// Commment : Control of a compatible LCD (1...4 rows by 1...4 columns) from
// a bus I2C with an EXPANDER of I/O with connection I2C.
// The tests of these routines have been programmed using the IC
// Phillips PCF8574T. I've used 4 bits mode programming.
// The 8 bits mode programming is possible if you use 2 x PCF8574T.
// RW Pin is not being used.
//
// As defined in the following structure the pin connection is as follows:
//
// PCF8574P LCD
// ======== ======
// P0 RS
// P1 RW (Not used!)
// P2 Enable
// P3 Led Backlight
// P4 D4
// P5 D5
// P6 D6
// P7 D7
//
// The SCL and SDA pins should be pull-up resistor as shown below:
//
// +5v
// |
// <
// > 4.7K
// <
//To PIC | To i2c slave
//pin xx ------------------ SDA pin
//(SDA)
// +5v
// |
// <
// > 4.7K
// <
//To PIC | To i2c slave
//pin xx ------------------ SCL pin
//(SCL)
//
//To PIC To i2c slave
//Vss pin ----------------- Vss or ground pin
// |
// -----
// --- Ground
// -
//
// THIS DOCUMENT IS PROVIDED TO THE USER "AS IS"
//-----------------------------------------------------------------------------
//--------------------------------------------------
//
//
//
//
//************************************************************************************
#define LCD_ADDR 0x3F //I2C slave address for LCD module
#define lcd_total_rows 2 //Number of rows: 1,2,3 or 4
#define lcd_total_columns 16 //Number of columns: 1...20
#define RS 0b00000001 //P0 - PCF8574T Pin connected to RS
#define RW 0b00000010 //P1 - PCF8574T Pin connected to RW
#define ENABLE 0b00000100 //P2 - PCF8574T Pin connected to EN
#define LCD_BACKLIGHT 0b00001000 //P3 - PCF8574T Pin connected to BACKLIGHT LED
#define addr_row_one 0x00 //LCD RAM address for row 1
#define addr_row_two 0x40 //LCD RAM address for row 2
#define addr_row_three 0x14 //LCD RAM address for row 3
#define addr_row_four 0x54 //LCD RAM address for row 4
#define ON 1
#define OFF 0
#define NOT ~
#define data_shifted data<<4
int8 new_row_request=1, BACKLIGHT_LED=LCD_BACKLIGHT;
void lcd_backlight_led(byte bl)
{
If (bl) BACKLIGHT_LED=LCD_BACKLIGHT; else BACKLIGHT_LED=OFF;
}
void i2c_send_nibble(byte data, byte type)
{
switch (type)
{
case 0 :
i2c_write(lcd_kanal,data_shifted | BACKLIGHT_LED);
delay_cycles(1);
i2c_write(lcd_kanal,data_shifted | ENABLE | BACKLIGHT_LED );
delay_us(2);
i2c_write(lcd_kanal,data_shifted & NOT ENABLE | BACKLIGHT_LED);
break;
case 1 :
i2c_write(lcd_kanal,data_shifted | RS | BACKLIGHT_LED);
delay_cycles(1);
i2c_write(lcd_kanal,data_shifted | RS | ENABLE | BACKLIGHT_LED );
delay_us(2);
i2c_write(lcd_kanal,data_shifted | RS | BACKLIGHT_LED); //fix
break;
}
}
void lcd_send_byte(byte data, byte type)
{
i2c_start(lcd_kanal);
i2c_write(lcd_kanal,LCD_ADDR);
i2c_send_nibble( data >> 4 , type);
i2c_send_nibble( data & 0xf , type);
i2c_stop(lcd_kanal);
}
void lcd_clear()
{
lcd_send_byte(0x01,0);
delay_ms(2);
new_row_request=1;
}
void lcd_init(void)
{
byte i;
byte CONST lcd_type=2; // 0=5x7, 1=5x10, 2=2 lines
byte CONST LCD_INIT_STRING[4] = {0x20 | (lcd_type << 2), 0xc, 1, 6}; // These bytes need to be sent to the LCD to start it up.
disable_interrupts(GLOBAL);
delay_ms(50); //LCD power up delay
i2c_start(lcd_kanal);
i2c_write(lcd_kanal,LCD_ADDR);
i2c_send_nibble(0x00,0);
delay_ms(15);
for (i=1;i<=3;++i)
{
i2c_send_nibble(0x03,0);
delay_ms(5);
}
i2c_send_nibble(0x02,0);
delay_ms(5);
i2c_stop(lcd_kanal);
for (i=0;i<=3;++i) {
lcd_send_byte(LCD_INIT_STRING[i],0);
delay_ms(5);
}
lcd_clear(); //Clear Display
enable_interrupts(GLOBAL);
}
void lcd_gotoxy( byte x, byte y)
{
byte row,column,row_addr,lcd_address;
static char data;
if (y>lcd_total_rows) row=lcd_total_rows; else row=y;
switch(row)
{
case 1: row_addr=addr_row_one; break;
case 2: row_addr=addr_row_two; break;
case 3: row_addr=addr_row_three; break;
case 4: row_addr=addr_row_four; break;
default: row_addr=addr_row_one; break;
}
if (x>lcd_total_columns) column=lcd_total_columns; else column=x;
lcd_address=(row_addr+(column-1));
lcd_send_byte(0x80|lcd_address,0);
}
//Display the character on LCD screen.
void LCD_PUTC(char in_data)
{
switch(in_data)
{
case '\f': lcd_clear(); break;
case '\n':
new_row_request++;
if (new_row_request>lcd_total_rows) new_row_request=1;
lcd_gotoxy(1, new_row_request);
break;
case '\b': lcd_send_byte(0x10,0); break;
default: lcd_send_byte(in_data,1); break;
}
}
//**************************BIG_NUMBERS X X L ****************************************
// -- BIG_NUMBERS X X L BIG_NUMBERS X X L BIG_NUMBERS X X L BIG_NUMBERS X X L----
//***************************************************************************************
const int8 bigNums[10][6] = {
{7, 0, 5, 4, 1, 6}, //0
{0, 5, 254, 1, 255, 1}, //1
{0, 2, 5, 7, 3, 1}, //2
{0, 2, 5, 1, 3, 6}, //3
{7, 3, 255, 254, 254, 255}, //4
{7, 2, 0, 1, 3, 6}, //5
{7, 2, 0, 4, 3, 6}, //6
{0, 0, 5, 254, 7, 254}, //7
{7, 2, 5, 4, 3, 6}, //8
{7, 2, 5, 1, 3, 6}, //9
};
const int8 lcd_custom_chars[] = { //int idi int8 yaptim dspic te duzeldi +++++++++++++++++++++
31, 31, 31, 0, 0, 0, 0, 0, // Small top line - 0
0, 0, 0, 0, 0, 31, 31, 31, // Small bottom line - 1
31, 0, 0, 0, 0, 0, 31, 31, // Small lines top and bottom -2
0, 0, 0, 0, 0, 0, 31 ,31, // Thin bottom line - 3
31, 31, 31, 31, 31, 15, 7, 7, // Left bottom chamfer full - 4
28, 30, 31, 31, 31, 31, 31, 31, // Right top chamfer full -5
31, 31, 31, 31, 31, 30, 28, 28, // Right bottom chamfer full -6
7, 15, 31, 31, 31, 31, 31, 31, // Left top chamfer full -7
};
void lcd_load_custom_chars(void)
{
int16 i;
// Set address counter pointing to CGRAM address 0.
// lcd_send_byte(0, 0x40);
lcd_send_byte(0x40, 0); // Reverse the parameter order
// Load custom lcd character data into CGRAM.
// It can only hold a maximum of 8 custom characters.
for(i = 0; i < sizeof(lcd_custom_chars); i++)
{
// lcd_send_byte(1, lcd_custom_chars[i]);
lcd_send_byte(lcd_custom_chars[i], 1); // Reverse the parameter order
}
// Set address counter pointing back to the DDRAM.
// lcd_send_byte(0, 0x80);
lcd_send_byte(0x80, 0); // Reverse the parameter order
}
void printBigNum(int number, int startCol, int startRow)
{
// Position cursor to requested position (each char takes 3 cols plus a space col)
lcd_gotoxy(startCol, startRow);//setCuror++++++++++++++++++++++++++++++++
// Each number split over two lines, 3 chars per line. Retrieve character
// from the main array to make working with it here a bit easier.
unsigned int8 thisNumber[6];
for (int cnt = 0; cnt < 6; cnt++) {
thisNumber[cnt] = bigNums[number][cnt];
}
// First line (top half) of digit
for (int cnt2 = 0; cnt2 < 3; cnt2++) {
lcd_putc((char)thisNumber[cnt2]);
}
// Now position cursor to next line at same start column for digit
lcd_gotoxy(startCol, startRow + 1);
// 2nd line (bottom half)
for (int cnt3 = 3; cnt3 < 6; cnt3++) {
lcd_putc((char)thisNumber[cnt3]);
}
}
//**************************BIG_NUMBERS X X L ****************************************
// -- BIG_NUMBERS X X L BIG_NUMBERS X X L BIG_NUMBERS X X L BIG_NUMBERS X X L----
//*************************************************************************************** |
|
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9297 Location: Greensville,Ontario
|
|
Posted: Tue Aug 20, 2019 8:57 am |
|
|
hmm, if you run the I2C scanner program does it see the LCD unit at address 0x3F ? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19620
|
|
Posted: Tue Aug 20, 2019 10:14 am |
|
|
I'd say no.
Screaming probability is that this is a 7bit address.
PIC's require the address in 8bit format. So 0x7E (0x3F<<1).
Quite simply a device cannot have a write address of 0x3F in 8bit format.
Write addresses must always be _even_ numbers when in 8bit
format.
Would explain it not working..... |
|
|
camleot23
Joined: 16 Aug 2019 Posts: 52
|
|
Posted: Wed Aug 21, 2019 1:52 am |
|
|
Yes, exactly the what Ttelmah said. I have solved the problem and I come here to say this and I saw Ttelmah's comment. You are very wise and knowledged. Thank you very much. I solved the problem. From this moment, I always run the I2C Scanner program first. And Ttelmah, #use delay is working with
Code: | #use delay(internal=28MHz)
setup_oscillator(OSC_INTERNAL,28000000); |
like this. I haven't tried 7.37Mhz yet but I guess that will probably work too.
Thank you all again.
Yasir |
|
|
|
|
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
|
Powered by phpBB © 2001, 2005 phpBB Group
|