Program ECIO without flowcode

For E-blocks user to discuss using E-blocks and programming for them.

Moderators: Benj, Mods

Post Reply
niiayi22
Posts: 8
Joined: Mon Mar 08, 2010 3:07 pm

Program ECIO without flowcode

Post by niiayi22 »

Hi. I'm using the ECIO28P for my University final year project to control a motor using USB interface. I was told that it was a simpler solution to use this E-block but i'm finding it dificult to program the chip without using Flowcode. I cannot use flowcode for my project as i need to demonstrate my programming ability. I want to use MPLAB C complier to build the hex file and somehow program the chip (i've tried using the ECIO programmer but it doesnt seem to work...only using the "complie to chip" in flowcode demo version allows me to build a program successfully). Any help will be much appreciated..thanks

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Program ECIO without flowcode

Post by Benj »

Hello

Shame you cant use Flowcode but I have some ideas to get you up and running.

If your using the C18 compiler then you first need to create an alternate linker file. This linker file is available with the Microchip USB examples that use a Bootloader. I have attached a valid linker file for the 18F4550 that can be included into your program and will work with either PIC ECIO device. Eg 2455 and 4455 compatible. The linker file simply specifies where the generated code gets placed in memory.

If you are using the Hi Tech compiler then you need to provide extra parameters to the linker.
Instead of something similar to this.

Params = --CHIP=18F4455 -N48 Test.c

you need to use something like this

Params = --CHIP=18F4455 -N48 Test.c --CODEOFFSET=800h --ROM=default,-0-7FF --OUTPUT=inhx032

Once you have this in place everything should be ok and you should be able to use the ECIOprog programming tool to load in your hex files.
Attachments
rm18f4550.zip
(590 Bytes) Downloaded 330 times

niiayi22
Posts: 8
Joined: Mon Mar 08, 2010 3:07 pm

Re: Program ECIO without flowcode

Post by niiayi22 »

Thanks. Managed to get it working! can send programs to Pic now. However i'm having a problem with my pwm code i've made in assembly code. I've tested the code on a circuit simulator (editing it for a different PIC) and it works fine so i know the PWM registers are correct (CCP2CON, T2CON, PR2 etc) . I'm assuming the frequency is set at 48Mhz as i dont want to be fiddling with configuration bits since the USB bootloader will have some kind of oscillator settings for the USB. Can you confirm this?... I'm trying to use PortB bit 3 for the PWM [RB3(AN9\CCP2)]. Is this possible? and how would i go about setting the PWM to this specific bit as there is also a CCP2 on pin RC1.


Also, i cannot seem to set PortA bit 0 and 1 as inputs?? i need these for ADC (AN0 and AN1) I'm happy so long as as these issues are possible to resolve outside flowcode (since i cannot use it for my project)
Thanks

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Program ECIO without flowcode

Post by Benj »

Hello,

Yes the ECIO runs at 48MHz. Regarding your PortA problem have you initialised the adcon1 register?

Here is a snippet of assembler that should control the alternate PWM pin.

FCD_PWM0_E_0003E_arg_nIdx EQU 0x00000024 ; bytes:1
FCD_PWM0_S_00040_arg_nIdx EQU 0x00000024 ; bytes:1
FCD_PWM0_S_00040_arg_nDuty EQU 0x00000025 ; bytes:1

ORG 0x0000080C
FCD_PWM0_S_00040
; { FCD_PWM0_SetDutyCycle ; function begin
DECF FCD_PWM0_S_00040_arg_nIdx, W
BNZ label1
MOVF FCD_PWM0_S_00040_arg_nDuty, W
MOVWF gbl_ccpr1l
label1
MOVLW 0x02
CPFSEQ FCD_PWM0_S_00040_arg_nIdx
RETURN
MOVF FCD_PWM0_S_00040_arg_nDuty, W
MOVWF gbl_ccpr2l
RETURN
; } FCD_PWM0_SetDutyCycle function end

ORG 0x00000820
FCD_PWM0_E_0003E
; { FCD_PWM0_Enable ; function begin
SETF gbl_pr2
MOVLW 0x04
MOVWF gbl_t2con
DECF FCD_PWM0_E_0003E_arg_nIdx, W
BNZ label2
MOVLW 0x0C
MOVWF gbl_ccp1con
BCF gbl_trisc,2
label2
MOVLW 0x02
CPFSEQ FCD_PWM0_E_0003E_arg_nIdx
RETURN
MOVLW 0x0C
MOVWF gbl_ccp2con
BCF gbl_trisb,3
RETURN
; } FCD_PWM0_Enable function end

ORG 0x0000083E
main
; { main ; function begin
MOVLW 0x0F
MOVWF gbl_adcon1
MOVLW 0x08
MOVWF gbl_ucfg
BCF gbl_pie2,5
MOVLW 0x02
MOVWF FCD_PWM0_E_0003E_arg_nIdx
CALL FCD_PWM0_E_0003E
MOVLW 0x02
MOVWF FCD_PWM0_S_00040_arg_nIdx
MOVLW 0x80
MOVWF FCD_PWM0_S_00040_arg_nDuty
CALL FCD_PWM0_S_00040
label3
BRA label3
; } main function end


We use the following assembler information as the config word.

ORG 0x00300000
DW 0x0E20
DW 0x1E3E
DW 0x8100
DW 0x0081
DW 0x800F
DW 0xA00F
DW 0x000F

niiayi22
Posts: 8
Joined: Mon Mar 08, 2010 3:07 pm

Re: Program ECIO without flowcode

Post by niiayi22 »

Ignore the PortA input question i was being very stupid (i asked this question after a long 9 hours of staring at code). I can see AN0 and AN1 as inputs..

Thanks for confirming the clock speed. I originally had the PWM settings to work with 4MHZ because the module has an external oscillator (which i thought was being used for this)

Okay i'm going to give that code a try now...i actually found this out in the p18f2455 data sheet but i soon realised that changing the CCP2MX bit was tricky in assembler.
One more quesion! Has the ECIO module automatically changed the PBADEN bit to off ? meaning that PORTB is set for digital input/output and NOT analogue input?

Thanks alot, will reply when i've tried the PWM again.

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Program ECIO without flowcode

Post by Benj »

Hello,

Port B is configured as digital on startup but you can still use any of the analogue compatible pins for analogue inputs. You simply have to control the adcon registers and the port tris registers and then the pins can be in either mode.

The 4MHz crystal on the ECIO drives the PLL that clocks the device at 48MHz (12MIPs).

niiayi22
Posts: 8
Joined: Mon Mar 08, 2010 3:07 pm

Re: Program ECIO without flowcode

Post by niiayi22 »

If i use C18 code. cannot i not just use:
#pragma config CCP2MX=OFF , at the beginning of my code? Doesnt seem to work! I have it placed before my "void main (void)" function but still getting PWM signal on portC bit1

Post Reply