mael diy
/
pwm_ground_npn_with_variable_duty_cycle_7seg_display
pwm ground command interface through optocoupler with display on 8 characters 7 segment
Revision 0:698108eb3db3, committed 2018-02-20
- Comitter:
- maeldiy
- Date:
- Tue Feb 20 09:50:03 2018 +0000
- Commit message:
- pwm ground command interface with display
Changed in this revision
diff -r 000000000000 -r 698108eb3db3 .gitignore --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.gitignore Tue Feb 20 09:50:03 2018 +0000 @@ -0,0 +1,4 @@ +.build +.mbed +projectfiles +*.py*
diff -r 000000000000 -r 698108eb3db3 README.md --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/README.md Tue Feb 20 09:50:03 2018 +0000 @@ -0,0 +1,75 @@ +# Getting started with Blinky on mbed OS + +This guide reviews the steps required to get Blinky working on an mbed OS platform. + +Please install [mbed CLI](https://github.com/ARMmbed/mbed-cli#installing-mbed-cli). + +## Import the example application + +From the command-line, import the example: + +``` +mbed import mbed-os-example-blinky +cd mbed-os-example-blinky +``` + +### Now compile + +Invoke `mbed compile`, and specify the name of your platform and your favorite toolchain (`GCC_ARM`, `ARM`, `IAR`). For example, for the ARM Compiler 5: + +``` +mbed compile -m K64F -t ARM +``` + +Your PC may take a few minutes to compile your code. At the end, you see the following result: + +``` +[snip] ++----------------------------+-------+-------+------+ +| Module | .text | .data | .bss | ++----------------------------+-------+-------+------+ +| Misc | 13939 | 24 | 1372 | +| core/hal | 16993 | 96 | 296 | +| core/rtos | 7384 | 92 | 4204 | +| features/FEATURE_IPV4 | 80 | 0 | 176 | +| frameworks/greentea-client | 1830 | 60 | 44 | +| frameworks/utest | 2392 | 512 | 292 | +| Subtotals | 42618 | 784 | 6384 | ++----------------------------+-------+-------+------+ +Allocated Heap: unknown +Allocated Stack: unknown +Total Static RAM memory (data + bss): 7168 bytes +Total RAM memory (data + bss + heap + stack): 7168 bytes +Total Flash memory (text + data + misc): 43402 bytes +Image: .\.build\K64F\ARM\mbed-os-example-blinky.bin +``` + +### Program your board + +1. Connect your mbed device to the computer over USB. +1. Copy the binary file to the mbed device. +1. Press the reset button to start the program. + +The LED on your platform turns on and off. + +## Export the project to Keil MDK, and debug your application + +From the command-line, run the following command: + +``` +mbed export -m K64F -i uvision +``` + +To debug the application: + +1. Start uVision. +1. Import the uVision project generated earlier. +1. Compile your application, and generate an `.axf` file. +1. Make sure uVision is configured to debug over CMSIS-DAP (From the Project menu > Options for Target '...' > Debug tab > Use CMSIS-DAP Debugger). +1. Set breakpoints, and start a debug session. + +![Image of uVision](img/uvision.png) + +## Troubleshooting + +If you have problems, you can review the [documentation](https://os.mbed.com/docs/latest/tutorials/debugging.html) for suggestions on what could be wrong and how to fix it.
diff -r 000000000000 -r 698108eb3db3 img/uvision.png Binary file img/uvision.png has changed
diff -r 000000000000 -r 698108eb3db3 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Tue Feb 20 09:50:03 2018 +0000 @@ -0,0 +1,176 @@ +#include "mbed.h" +// the MAX7219 address map (datasheet table 2) +#define MAX7219_DECODE_REG (0x09) +#define MAX7219_INTENSITY_REG (0x0A) +#define MAX7219_SCANLIMIT_REG (0x0B) +#define MAX7219_SHUTDOWN_REG (0X0C) +#define MAX7219_DISPLAYTEST_REG (0x0F) +#define MAX7219_DIGIT_REG(pos) ((pos) + 1) + +// shutdown mode (datasheet table 3) +#define MAX7219_OFF (0x0) +#define MAX7219_ON (0x1) + +// digit pattern for a 7-segment display. datasheet table 5 +const char digit_pattern[16] = +{ + 0x7E, // 0 + 0x30, // 1 + 0x6D, // 2 + 0x79, // 3 + 0x33, // 4 + 0x5B, // 5 + 0x5F, // 6 + 0x70, // 7 + 0x7F, // 8 + 0x7B, // 9 + 0x77, // A + 0x1F, // b + 0x4E, // C + 0x3D, // d + 0x4F, // E + 0x47 // F +}; + +const float step=0.001; //step for push button pwm will increase or decrease by this value when pushing + +const float MIN =0; // PWM rate bounds +const float MAX =1; +const int PWM_period = 10; // pwm period in ms + +Serial pc(SERIAL_TX,SERIAL_RX); +//DigitalOut myled(LED1); +DigitalIn set_plus(PB_5); //input for increasing pwm cycle +DigitalIn set_less(PB_4); //input for decreasing pwm cycle +DigitalIn safe_or_button(PB_10); //input for setting pot or button as master +// DigitalIn pause(a definir); //input for setting pause and returning to last value, this to avoid waiting to go up to last value +long n,u,d,c,m, dm,ddm,cm,mm; // pour l'afficheur +void fermeture(); // relais 1 & 3 fermés +void ouverture(); // relais 2 & 4 fermés +void neutre(); // tout relais ouverts +PwmOut my_pwm(PF_9); +float pot_value = 0; +int pot_value_display = 0; +int pot_pause = 0; // buffer value when setting in pause +//SPI spimax(D11, D12, D13); DigitalOut CS(D9); // pins for F411RE +//mosi , miso, clk +SPI spimax(PA_7, PA_6, PA_5); DigitalOut CS(D8); //pins for F767ZI + +void max7219(char reg,char dta) { CS = 0; spimax.write(reg); spimax.write(dta); CS = 1; } // function to write to max7219 7 seg display + +float bound(float value) // bound value when push buttons are activated too long +{ + if(value < MIN) + return MIN; + else if(value > MAX) + return MAX; + else + return value; +} + +void init_max7219() +{ + // Turn on the display + max7219(MAX7219_SHUTDOWN_REG, MAX7219_ON); + // enable test mode. datasheet table 10 + max7219(MAX7219_DISPLAYTEST_REG, MAX7219_ON); + wait(1); + // disable test mode. datasheet table 10 + max7219(MAX7219_DISPLAYTEST_REG, MAX7219_OFF); + // set medium intensity. datasheet table 7 + max7219(MAX7219_INTENSITY_REG, 0x5); + // turn off display. datasheet table 3 + // max7219(MAX7219_SHUTDOWN_REG, MAX7219_OFF); + // drive 8 digits. datasheet table 8 + max7219(MAX7219_SCANLIMIT_REG, 7); + // no decode mode for all positions. datasheet table 4 + max7219(MAX7219_DECODE_REG, 0x00); + for(int i = 1; i < 9; i++) // delete all chars + { + max7219(i,0x01); + } +} + +int main() { + +set_plus.mode(PullDown); +set_less.mode(PullDown); +safe_or_button.mode(PullDown); +init_max7219(); + pc.printf("end init"); + max7219(1,digit_pattern[0]); + max7219(2,digit_pattern[0]); + max7219(3,digit_pattern[0]); + + max7219(8,digit_pattern[5]); // writing "safe" + max7219(7,digit_pattern[10]); + max7219(6,digit_pattern[15]); + max7219(5,digit_pattern[14]); + // Set PWM + my_pwm.period_ms(PWM_period); + +while(1) { + + if (safe_or_button == 0) { + // pot_value = pot.read(); + pot_value = 0; + my_pwm.write(pot_value); // sets duty cycle directly through reading normalised pot value + // pc.printf("safe_or_button =0 setting PWM to 0%"); + max7219(1,digit_pattern[0]); + max7219(2,digit_pattern[0]); + max7219(3,digit_pattern[0]); + + max7219(8,digit_pattern[5]); // writing "safe" + max7219(7,digit_pattern[10]); + max7219(6,digit_pattern[15]); + max7219(5,digit_pattern[14]); + } + else + for(int i = 4; i < 9; i++) // delete "safe" writing + { + max7219(i,0x00); + } + // if pause = 1 break + if (set_plus == 1) { + pot_value = bound(pot_value + step); + // pc.printf("safe_or_button value ==1, set_plus =1"); + pc.printf(" pot_value : "); + pc.printf("%f\n",pot_value); + + my_pwm.write(pot_value); // sets duty cycle directly through reading normalised pot value + pot_value_display = int (1000 * pot_value); + c = pot_value_display/100; + d = pot_value_display/10 - 10*c; + u = pot_value_display - 100*c - 10*d; + max7219(1,digit_pattern[u]); + max7219(2,digit_pattern[d]); + max7219(3,digit_pattern[c]); + wait_ms(40); // to avoid taking more than one or 2 button press + } + else if (set_less == 1) { + pot_value = bound(pot_value - step); + // pc.printf("safe_or_button value ==1, set_less =1"); // button state display on serial monitor + pc.printf(" pot_value : "); + pc.printf("%f\n",pot_value); + my_pwm.write(pot_value); // sets duty cycle directly through reading normalised pot value + for(int i = 4; i < 7; i++) // delete "safe" writing + { + max7219(i,0x00); + } + pot_value_display = int (1000 * pot_value); + c = pot_value_display/100; + d = pot_value_display/10 - 10*c; + u = pot_value_display - 100*c - 10*d; + max7219(1,digit_pattern[u]); + max7219(2,digit_pattern[d]); + max7219(3,digit_pattern[c]); + wait_ms(40); // to avoid taking more than one or 2 button press + } + // pot_pause = pot_value // pas bon + } + + +} + + + \ No newline at end of file
diff -r 000000000000 -r 698108eb3db3 mbed-os.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed-os.lib Tue Feb 20 09:50:03 2018 +0000 @@ -0,0 +1,1 @@ +https://github.com/ARMmbed/mbed-os/#eca67ca7dafab4ef70c21e2463b541132d0dd691