Sonsivri
 
*
Welcome, Guest. Please login or register.
Did you miss your activation email?
December 09, 2016, 06:31:54 18:31


Login with username, password and session length


Pages: [1]
Print
Author Topic: Mikrobasic Pro to Proton ? (PIC4550)  (Read 5593 times)
0 Members and 1 Guest are viewing this topic.
orpheedulogis
Junior Member
**
Offline Offline

Posts: 61

Thank You
-Given: 9
-Receive: 1


« on: October 11, 2010, 09:41:07 21:41 »

Hi all

I did a sofware for an electric motorcyle with Mikrobasic.
It was OK except ... it did strange things now, just because soft is more big than before.
For explanation: soft works (speed display, current, cell voltage, time...) but, if I add this in main :

Code:
if Condition then
   ProcedureXY
end if

Soft seems not to be correct anumore, even if condition false !
(in fact I tried to replace "if" by "goto" to be sure conition was not ok and it does the same thing ! )

So I decided to try translation to Proton, if it's not too hard  Embarrassed

I think the longest problem is to configure correctly PIC (in fact it's a PIC4553, not 4550 but they have same use)
Is someone able to traduce folowing (mikrobasic) code for me, that's would be great.


Quote
program Ysr18
' (=Ysr17 -> suppression du cycle analyst et des cell-log)
'----------------------------------------------------------------
'Configuration:
' Regler le MCU clock a 48Mhz ! (96Mhz/2)
'CPU pre-scaler -> divisé par 5 pour obtenir 20/5=4 Mhz qui devient ensuite le 48Mhz de façon interne
'CPU Systemclock Postscaler OSC1/OSC2 Src:/1 96Mhz PLL Src:/2
'Full USB Clock source: Clock src from OSC1/OSC2
'Oscillator: HSHS+PLL, USB+HS
'Fail Safe Clock: Disable
'Internal/Extarnal switch: Disabled
'Power up timer: Disabled
'Brown Out Detect: Enabled in hardware, SBOREN disabled
'Brown out voltage: 2.0V
'USB Voltage: Disabled
'Watchdog Timer: Disabled-Controled by SWDTEN bit
'Watchdog Poscaler: 1:32768
'Port B A/D Enabled: PORTB configured as digital I/O on RESET
'Master Clear Enable: MCLR enabled, RE3 Disabled
'Stack overfow Reset: Enabled
'Low voltage Program: Disabled
'Boot Block Size Select 1KW

'Reste: Disabled

'----------------------------------------------------------------

'entrées
symbol TensionCell   = PORTA.0
symbol GlobalCurrent = PORTA.1
symbol GlobalVoltage = PORTA.2
symbol ChargeurIn    = PORTA.4
symbol SpeedPulse    = PORTB.0
symbol RFIDin        = PORTB.1
symbol BrakeIn       = PORTC.4
symbol InMove        = PORTC.5
symbol NeSertPlus    = PORTC.7
symbol InNoir        = PORTD.0
symbol InRouge       = PORTD.1
symbol PhareIn       = PORTD.2
symbol ClignotantIn  = PORTD.3
symbol InJaune       = PORTE.1

'sorties
symbol RsLcd       = PORTA.3
symbol EnLcd       = PORTA.5
symbol SelectAudio = PORTB.2
symbol ADCsel1B    = PORTB.3 '=D6 lcd
symbol ADCsel2B    = PORTB.6 '=D4 lcd
symbol ADCsel2A    = PORTB.7 '=D5 lcd
symbol PowerRL2    = PORTC.0
symbol ADCsel1A    = PORTC.1 '=D7 lcd
symbol LedClavier  = PORTC.2
symbol SortieTx    = PORTC.6
symbol PowerSyst   = PORTD.4
symbol Buzzer      = PORTD.5
symbol AlarmeOut   = PORTD.6
symbol WPEeprom    = PORTD.7
symbol BrakeOut    = PORTE.0
symbol ForcePower  = PORTE.2

'timer
Symbol TMR0IE = INTCON.5 ' TMR0 Overflow Interrupt Enable
Symbol TMR0IF = INTCON.2 ' TMR0 Overflow Interrupt Flag
Symbol TMR1IE = PIE1.0   ' TMR1 Overflow Interrupt Enable
Symbol TMR1IF = PIR1.0   ' TMR1 Overflow Interrupt Flag
Symbol TMR2IE = PIE1.1   ' TMR2 to PR2 Match Interrupt Enable
Symbol TMR2IF = PIR1.1   ' TMR2 to PR2 Match Interrupt Flag

'constantes
const DelaiAlarme = 254
const DelaiPosition =500
const DelaiTresTresCourt = 90
const DelaiCourt = 180
const PositionPremierBitAnalyst=29
const AdresseDistanceTotale =12 '(et 13,14,15)
const AdresseRapportVitesse =16 '(et 17) rapport de conversion Vitesse (6.25 au départ)
const AdresseRapportTension50V =18 '(et 19) rapport de conversion Tension (52 au départ)
const AdresseRapportTension3V7 =20 '(et 21) rapport de conversion Tension (4.85 au départ)
const AdresseRapportCourant =22 '(et 23) rapport de conversion courant (11.6 au départ)
const AdressePointZeroCourant = 24 '(et 25) point de référence négatif/positif (1182 au départ)
const AdresseAmperesHeure =26 '(et 27)
const AdresseTempsCharge =28 '(et 29)

const AdresseCourbeCharge1 =200 '(2040 points possibles, enregistrés en word)
const AdresseCourbeCharge2 =2300 '(2040 points possibles, enregistrés en word)
const AdresseCourbeDecharge1 =4300 '(2040 points possibles, enregistrés en word)
const AdresseCourbeDecharge2 =6400 '(2040 points possibles, enregistrés en word)

const Decalage=10

'variables
dim Soft_I2C_Scl as sbit at RB5_bit
dim Soft_I2C_Sda as sbit at RB4_bit
dim Soft_I2C_Scl_Direction as sbit at TRISB5_bit 'définit le clock I2C
dim Soft_I2C_Sda_Direction as sbit at TRISB4_bit 'définit le data I2C

' Lcd module connections
dim LCD_RS as sbit at RA3_bit
    LCD_EN as sbit at RA5_bit
    LCD_D4 as sbit at RB6_bit
    LCD_D5 as sbit at RB7_bit
    LCD_D6 as sbit at RB3_bit
    LCD_D7 as sbit at RC1_bit

dim LCD_RS_Direction as sbit at TRISA3_bit
    LCD_EN_Direction as sbit at TRISA5_bit
    LCD_D4_Direction as sbit at TRISB6_bit
    LCD_D5_Direction as sbit at TRISB7_bit
    LCD_D6_Direction as sbit at TRISB3_bit
    LCD_D7_Direction as sbit at TRISC1_bit

.........
...........
............



'DEBUT DU PROGRAMME PRINCIPAL
'note: si la TensionGlobale est nulle (au lieu de 53V) le système est en mode démo
main:

TRISA  = %00010111         ' PORT A (1=entrée, 0=sortie)
TRISB  = %00000011         ' PORT B
TRISC  = %10110000         ' PORT C
TRISD  = %00001111         ' PORT D
TRISE  = %00000010         ' PORT E

PortA=%00110000 ' on met le LCD enable au niveau haut car actif front descendant
PortB=%00000000
PortC=%00100000
PortD=%10000000 'on met WP au Niveau haut pour interdire l'écriture sur l'Eeprom
PortE=%00000000

UART1_Init(9600)

Delay_Ms(250)  ' attente de stabilisation

'------------------------------------
' réglage du timer
'configuration de l'interrupt du timer2
'T2CON = %01111111 ' Set T2CON.2
'TMR2IF=0
'TMR2IE=0
'TMR2=0
'PR2=190'5

CMCON = 0X07        ' Turn off all comparators.
INTCON=0 'pas d'interruption
ADCON0 = 0x01       ' choix canal convertisseur A/D (ici=1)
ADCON1 = 0X00       ' Reset registre A/D 1.
ADCON1 = %1100  ' activation AN2,AN1,AN0
soft_I2C_init()
Lcd_Init()
Lcd_Cmd(_LCD_CURSOR_OFF)

INTCON.INT0IE = 1      ' autorise INTO  (=compteur vitesse)
INTCON.INT0IF = 0      ' flag INT0 à zéro
INTCON3.INT1IE = 1     ' autorise interruption INT1 (RFID)
INTCON3.INT1IF = 0     ' flag INT1 à zéro
INTCON3.INT1IP= 0      ' priorité basse
INTCON.INTEDG0=1
INTCON2.INTEDG1=1      ' selectionne front montant
INTCON.GIE = 1         ' autorise interruptions
UCON.USBEN = 0 'désactive l'USB sur port C4 et C5
UCFG.UTRDIS = 1 'désactive le transmetteur USB sur port C4 et C5


..........
...............
.................



Sorry, it's in french so, perhaps, not very clear.
Thanks for help



Logged
pickit2
Moderator
Hero Member
*****
Offline Offline

Posts: 3816

Thank You
-Given: 567
-Receive: 2049


There is no evidence that I muted SoNsIvRi


« Reply #1 on: October 12, 2010, 12:55:02 00:55 »

Here is a close to finish translation to Proton.you should be able to find missing part in proton manual.
Code:

'****************************************************************
'*  Name    : program Ysr18                                                                             *
'****************************************************************
' program Ysr18
' (=Ysr17 -> suppression du cycle analyst et des cell-log)
'----------------------------------------------------------------
Device  18F4553
'Configuration:
'Device 18F2550
Xtal = 48   
Config_Start
   PLLDIV = 5           ' Divide by 5 (20 MHz oscillator input)
   CPUDIV = OSC1_PLL2   ' [OSC1/OSC2 Src: /1][96 MHz PLL Src: /2]
   USBDIV = 2           ' USB clock source comes from the 96 MHz PLL divided by 2
   FOSC = HS            ' Internal oscillator, HS used by USB
   FCMEN = OFF          ' Fail-Safe Clock Monitor disabled
   IESO = OFF           ' Oscillator Switchover mode disabled
   PWRT = OFF           ' PWRT disabled
   BOR = On             ' Brown-out Reset enabled in hardware only (SBOREN is disabled)
   BORV = 3             ' Minimum setting
   VREGEN = Off         ' USB voltage regulator not enabled
   WDT = OFF            ' HW Disabled - SW Controlled
   WDTPS = 128          ' 1:128
   MCLRE = OFF          ' RE3 input pin enabled; MCLR disabled
   LPT1OSC = OFF        ' Timer1 configured for higher power operation
   PBADEN = Off         ' PORTB<4:0> pins are configured as analog input channels on Reset
   CCP2MX = On          ' CCP2 input/output is multiplexed with RC1
   STVREN = On          ' Stack full/underflow will cause Reset
   LVP = OFF            ' Single-Supply ICSP disabled
   XINST = OFF          ' Instruction set extension and Indexed Addressing mode disabled (Legacy mode)
   Debug = OFF          ' Background debugger disabled, RB6 and RB7 configured as general purpose I/O pins
Config_End

Declare Flash_Capable = FALSE
' Regler le MCU clock a 48Mhz ! (96Mhz/2)
'CPU pre-scaler -> divisé par 5 pour obtenir 20/5=4 Mhz qui devient ensuite le 48Mhz de façon interne
'CPU Systemclock Postscaler OSC1/OSC2 Src:/1 96Mhz PLL Src:/2
'Full USB Clock source: Clock src from OSC1/OSC2
'Oscillator: HSHS+PLL, USB+HS
'Fail Safe Clock: Disable
'Internal/Extarnal switch: Disabled
'Power up timer: Disabled
'Brown Out Detect: Enabled in hardware, SBOREN disabled
'Brown out voltage: 2.0V
'USB Voltage: Disabled
'Watchdog Timer: Disabled-Controled by SWDTEN bit
'Watchdog Poscaler: 1:32768
'Port B A/D Enabled: PORTB configured as digital I/O on RESET
'Master Clear Enable: MCLR enabled, RE3 Disabled
'Stack overfow Reset: Enabled
'Low voltage Program: Disabled
'Boot Block Size Select 1KW

'Reste: Disabled

'----------------------------------------------------------------

'entrées
Symbol TensionCell   = PORTA.0
Symbol GlobalCurrent = PORTA.1
Symbol GlobalVoltage = PORTA.2
Symbol ChargeurIn    = PORTA.4
Symbol SpeedPulse    = PORTB.0
Symbol RFIDin        = PORTB.1
Symbol BrakeIn       = PORTC.4
Symbol InMove        = PORTC.5
Symbol NeSertPlus    = PORTC.7
Symbol InNoir        = PORTD.0
Symbol InRouge       = PORTD.1
Symbol PhareIn       = PORTD.2
Symbol ClignotantIn  = PORTD.3
Symbol InJaune       = PORTE.1

'sorties
Symbol RsLcd       = PORTA.3
Symbol EnLcd       = PORTA.5
Symbol SelectAudio = PORTB.2
Symbol ADCsel1B    = PORTB.3 '=D6 lcd
Symbol ADCsel2B    = PORTB.6 '=D4 lcd
Symbol ADCsel2A    = PORTB.7 '=D5 lcd
Symbol PowerRL2    = PORTC.0
Symbol ADCsel1A    = PORTC.1 '=D7 lcd
Symbol LedClavier  = PORTC.2
Symbol SortieTx    = PORTC.6
Symbol PowerSyst   = PORTD.4
Symbol Buzzer      = PORTD.5
Symbol AlarmeOut   = PORTD.6
Symbol WPEeprom    = PORTD.7
Symbol BrakeOut    = PORTE.0
Symbol ForcePower  = PORTE.2

'timer
Symbol TMR0IE = INTCON.5 ' TMR0 Overflow Interrupt Enable
Symbol TMR0IF = INTCON.2 ' TMR0 Overflow Interrupt Flag
Symbol TMR1IE = PIE1.0   ' TMR1 Overflow Interrupt Enable
Symbol TMR1IF = PIR1.0   ' TMR1 Overflow Interrupt Flag
Symbol TMR2IE = PIE1.1   ' TMR2 to PR2 Match Interrupt Enable
Symbol TMR2IF = PIR1.1   ' TMR2 to PR2 Match Interrupt Flag

'constantes
Symbol DelaiAlarme = 254
Symbol DelaiPosition =500
Symbol DelaiTresTresCourt = 90
Symbol DelaiCourt = 180
Symbol PositionPremierBitAnalyst=29
Symbol AdresseDistanceTotale =12 '(et 13,14,15)
Symbol AdresseRapportVitesse =16 '(et 17) rapport de conversion Vitesse (6.25 au départ)
Symbol AdresseRapportTension50V =18 '(et 19) rapport de conversion Tension (52 au départ)
Symbol AdresseRapportTension3V7 =20 '(et 21) rapport de conversion Tension (4.85 au départ)
Symbol AdresseRapportCourant =22 '(et 23) rapport de conversion courant (11.6 au départ)
Symbol AdressePointZeroCourant = 24 '(et 25) point de référence négatif/positif (1182 au départ)
Symbol AdresseAmperesHeure =26 '(et 27)
Symbol AdresseTempsCharge =28 '(et 29)

Symbol AdresseCourbeCharge1 =200 '(2040 points possibles, enregistrés en word)
Symbol AdresseCourbeCharge2 =2300 '(2040 points possibles, enregistrés en word)
Symbol AdresseCourbeDecharge1 =4300 '(2040 points possibles, enregistrés en word)
Symbol AdresseCourbeDecharge2 =6400 '(2040 points possibles, enregistrés en word)

Symbol Decalage=10

'variables
Declare SCL_Pin PORTB.5
Declare SDA_Pin PORTB.4

'Dim Soft_I2C_Scl As sbit At RB5_bit
'Dim Soft_I2C_Sda As sbit At RB4_bit
'
'Hbusin
'Hbusout             ' below not needed?/
'Dim Soft_I2C_Scl_Direction As sbit At TRISB5_bit 'définit le clock I2C
'Dim Soft_I2C_Sda_Direction As sbit At TRISB4_bit 'définit le data I2C

' Lcd module connections
LCD_Type ALPHA
LCD_DTPin PORTB.0
LCD_ENPin PORTA.5
LCD_RSPin PORTA.3
'Dim LCD_RS As sbit At RA3_bit
'    LCD_EN As sbit At RA5_bit
'    LCD_D4 As sbit At RB6_bit
'    LCD_D5 As sbit At RB7_bit
'    LCD_D6 As sbit At RB3_bit
'    LCD_D7 As sbit At RC1_bit

'Dim LCD_RS_Direction As sbit At TRISA3_bit
'    LCD_EN_Direction As sbit At TRISA5_bit
'    LCD_D4_Direction As sbit At TRISB6_bit
'    LCD_D5_Direction As sbit At TRISB7_bit
'    LCD_D6_Direction As sbit At TRISB3_bit
'    LCD_D7_Direction As sbit At TRISC1_bit

'.........
'...........
'............



'DEBUT DU PROGRAMME PRINCIPAL
'note: si la TensionGlobale est nulle (au lieu de 53V) le système est en mode démo
main:

TRISA  = %00010111         ' PORT A (1=entrée, 0=sortie)
TRISB  = %00000011         ' PORT B
TRISC  = %10110000         ' PORT C
TRISD  = %00001111         ' PORT D
TRISE  = %00000010         ' PORT E

PORTA=%00110000 ' on met le LCD enable au niveau haut car actif front descendant
PORTB=%00000000
PORTC=%00100000
PORTD=%10000000 'on met WP au Niveau haut pour interdire l'écriture sur l'Eeprom
PORTE=%00000000

' UART1_Init(9600)

DelayMS 250  ' attente de stabilisation

'------------------------------------
' réglage du timer
'configuration de l'interrupt du timer2
'T2CON = %01111111 ' Set T2CON.2
'TMR2IF=0
'TMR2IE=0
'TMR2=0
'PR2=190'5

CMCON = 0X07        ' Turn off all comparators.
INTCON=0 'pas d'interruption
ADCON0 = 0x01       ' choix canal convertisseur A/D (ici=1)
ADCON1 = 0X00       ' Reset registre A/D 1.
ADCON1 = %1100  ' activation AN2,AN1,AN0

'not needed in [color=blueproton[/color]
' soft_I2C_init()
' Lcd_Init()
' Lcd_Cmd(_LCD_CURSOR_OFF)

[color=blue]' read proton manual to translate your need here[/color]
'INTCON.INT0IE = 1      ' autorise INTO  (=compteur vitesse)
'INTCON.INT0IF = 0      ' flag INT0 à zéro
'INTCON3.INT1IE = 1     ' autorise interruption INT1 (RFID)
'INTCON3.INT1IF = 0     ' flag INT1 à zéro
'INTCON3.INT1IP= 0      ' priorité basse
'INTCON.INTEDG0=1
'INTCON2.INTEDG1=1      ' selectionne front montant
'INTCON.GIE = 1         ' autorise interruptions

[color=blue]' See also : USBout, USBin, USBpoll. [/color]
'UCON.USBEN = 0 'désactive l'USB sur port C4 et C5
'UCFG.UTRDIS = 1 'désactive le transmetteur USB sur port C4 et C5


Logged

Note: If you have no posts other than, I want or reporting a dead link Then you can't complain If I remove your post So Stop Leeching
orpheedulogis
Junior Member
**
Offline Offline

Posts: 61

Thank You
-Given: 9
-Receive: 1


« Reply #2 on: October 12, 2010, 10:28:09 22:28 »

Thanks a lot pickit2.
But I found the actual problem with Mikrobasic: when main is too long (or perhaps "Select case", "if then..." part of main ), it make bugs. I found this removing line by line. So I tried to add new procedures instead of using main lines and it works perfectly.

I will try the conversion (in a few time) to proton but I wonder about:
- sending serial command
- using ADC
- sending Lcd datas.

If I can do this, I think I will be abble to translate Mikrobasic others things

Thanks again

You can see my project here: www.motoelectrique.unblog.fr
Logged
Pages: [1]
Print
Jump to:  


DISCLAIMER
WE DONT HOST ANY ILLEGAL FILES ON THE SERVER
USE CONTACT US TO REPORT ILLEGAL FILES
ADMINISTRATORS CANNOT BE HELD RESPONSIBLE FOR USERS POSTS AND LINKS

... Copyright © 2003-2999 Sonsivri.to ...
Powered by SMF 1.1.18 | SMF © 2006-2009, Simple Machines LLC | HarzeM Dilber MC